]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
growfs script: add swap partition as well as growing root
authorMike Karels <karels@FreeBSD.org>
Sat, 10 Dec 2022 19:38:36 +0000 (13:38 -0600)
committerMike Karels <karels@FreeBSD.org>
Fri, 13 Jan 2023 19:14:47 +0000 (13:14 -0600)
commitd6ee3d22f5c477902e79358ff96fefaee6d285d0
tree359a1f045f83ee9073f7ed615a45b1576a006404
parente51074735fa32fb48496bdc0dd3799eaf84afd19
growfs script: add swap partition as well as growing root

Add the ability to create a swap partition in the course of growing
the root file system on first boot, enabling by default.  The default
rules are: add swap if the disk is at least 15 GB (decimal), and the
existing root is less than 40% of the disk.  The default size is 10%
of the disk, but is limited by the memory size.  The limit is twice
memory size up to 4 GB, 8 GB up to 8 GB memory, and memory size over
8 GB memory. Swap size is clamped at vm.swap_maxpages/2 as well.
The new swap partition is labeled as "growfs_swap".

The default behavior can be overridden by setting growfs_swap_size in
/etc/rc.conf or in the kernel environment, with kenv taking priority.
A value of 0 inhibits the addition of swap, an empty value specifies
the default, and other values indicate a swap size in bytes.

By default, addition of swap is inhibited if a swap partition is found
in the output of the sysctl kern.geom.conftxt before the current root
partition, usually meaning that there is another disk present.
Swap space is not added if one is already present in /etc/fstab.

The root partition is read-only when growfs runs, so /etc/fstab can
not be modified.  That step is handled by a new growfs_fstab script,
added in a separate commit.  Set the value "growfs_swap_pdev" in kenv
to indicate that this should be done, as well as for internal use.

There is optional verbose output meant for debugging; it can only be
enabled by modifying the script (in two places, for sh and awk).
This should be removed before release, after testing on -current.

Discussed with: cperciva
Reviewed by: imp (previous version)
Differential Revision: https://reviews.freebsd.org/D37462

(cherry picked from commit 4a30d7bb373c08f42f953b9cd1e793e236b4cd92)
libexec/rc/rc.d/growfs