Page MenuHomeFreeBSD

D37462.id113526.diff
No OneTemporary

D37462.id113526.diff

diff --git a/libexec/rc/rc.d/growfs b/libexec/rc/rc.d/growfs
--- a/libexec/rc/rc.d/growfs
+++ b/libexec/rc/rc.d/growfs
@@ -1,5 +1,6 @@
#!/bin/sh
#
+# Copyright 2022 Michael J. Karels
# Copyright 2014 John-Mark Gurney
# All rights reserved.
#
@@ -63,6 +64,7 @@
growfs_start ()
{
+ verbose=0
echo "Growing root partition to fill device"
FSTYPE=$(mount -p | awk '{ if ( $2 == "/") { print $3 }}')
FSDEV=$(mount -p | awk '{ if ( $2 == "/") { print $1 }}')
@@ -100,19 +102,111 @@
diskdev=${rootdev}
fi
+ # Check kenv for growfs_swap_size; if not present,
+ # check $growfs_swap_size from /etc/rc.conf.
+ # A value of 0 suppresses swap addition,
+ # "" (or unset) specifies the default.
+ addswap=1
+ swapsize="$(kenv -q growfs_swap_size 2>/dev/null)"
+ case "$swapsize" in
+ "0") addswap=0
+ ;;
+ "") case "$growfs_swap_size" in
+ "0") addswap=0
+ ;;
+ "") ;;
+ *) swapsize="$growfs_swap_size"
+ ;;
+ esac
+ ;;
+ *) ;;
+ esac
+
+ [ $verbose -eq 1 ] && {
+ echo "diskdev is $diskdev"
+ echo "search is $search"
+ echo "swapsize is $swapsize"
+ }
+
sysctl -b kern.geom.conftxt | awk '
{
+ verbose = 0
lvl=$1
device[lvl] = $3
type[lvl] = $2
idx[lvl] = $7
+ offset[lvl] = $9
parttype[lvl] = $13
+ size[lvl] = $4
+ if (verbose) print lvl, type[lvl], $3
+ if (type[lvl] == "DISK") {
+ disksize = size[lvl]
+ if (verbose)
+ print "disksize ", disksize
+ if (addswap == 1 && (size[lvl] > 15000000000 || swapsize > 0))
+ doing_swap = 1
+ else
+ doing_swap = 0
+ } else if (type[lvl] == "PART" && $11 == "freebsd-swap" && \
+ int(swapsize) == 0) {
+ # This finds swap only if it precedes root, e.g. preceding disk.
+ addswap = 0
+ doing_swap = 0
+ print "swap device exists, not adding swap"
+ }
if (dev == $3) {
for (i = 1; i <= lvl; i++) {
# resize
if (type[i] == "PART") {
pdev = device[i - 1]
- cmd[i] = "gpart resize -i " idx[i] " " pdev
+ if (verbose)
+ print i, pdev, addswap, disksize, \
+ doing_swap
+ swapcmd = ""
+ # Allow swap if current root is < 40% of disk.
+ if (parttype[i] != "MBR" && doing_swap == 1 && \
+ (size[i] / disksize < 0.4 || \
+ swapsize > 0)) {
+ print "Adding swap partition"
+ sector = $5
+ if (int(swapsize) == 0) {
+ swapsize = \
+ int(disksize / sector / 10)
+ swaplim = 2 * physmem / sector
+ if (swapsize > swaplim)
+ swapsize = swaplim
+ }
+ if (verbose)
+ print "swapsize ", swapsize
+ align = 4 * 1024 * 1024 / sector
+
+ # Estimate offset for swap; let
+ # gpart compute actual start and size.
+ # Assume expansion all goes into this
+ # partition for MBR case.
+ if (parttype[i - 1] == "MBR") {
+ if (verbose)
+ print "sz ", size[i - 1], \
+ " off ", offset[i - 1]
+ expand = size[0] - \
+ (size[i - 1] + offset[i - 1])
+ } else {
+ if (verbose)
+ print "sz ", size[i], \
+ " off ", offset[i]
+ expand = size[0] - \
+ (size[i] + offset[i])
+ }
+ if (verbose)
+ print "expand ", expand, \
+ " sz ", size[i]
+ swapbase = (expand + size[i]) / sector
+ swapbase -= swapsize + align
+ swapcmd = "gpart add -t freebsd-swap -a " align " -b " swapbase " " pdev "; kenv growfs_swap_added=1 >/dev/null; "
+ if (verbose)
+ swapcmd = "set -x; " swapcmd
+ }
+ cmd[i] = swapcmd "gpart resize -i " idx[i] " " pdev
if (parttype[i] == "GPT")
cmd[i] = "gpart recover " pdev " ; " cmd[i]
} else if (type[i] == "LABEL") {
@@ -128,7 +222,8 @@
}
exit 0
}
-}' dev="$search"
+}' dev="$search" physmem="$(sysctl -n hw.physmem)" addswap="$addswap" \
+ swapsize="$swapsize"
gpart commit "$diskdev" 2> /dev/null
case "$FSTYPE" in
ufs)

File Metadata

Mime Type
text/plain
Expires
Sun, Jan 12, 2:51 PM (20 h, 52 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
15770242
Default Alt Text
D37462.id113526.diff (3 KB)

Event Timeline