Lines Matching +full:swap +full:- +full:size +full:- +full:gb
4 # Copyright 2014 John-Mark Gurney
35 # Grow root partition to fill available space, optionally adding a swap
37 # have it work on essentially any size drive.
41 # space on rootfs for the boot to succeed, and on images we ship - which are
42 # the primary purpose of this script - there is no separate /usr anyway.
55 sysctl -b kern.geom.conftxt |
58 if [ "${_type}" = "DISK" -a -n "$(echo ${_search} | grep ${_dev})" ]; then
59 echo -n ${_dev}
65 # Compute upper bound on swap partition size (if added), based on physmem
67 # Rule for swap size based on memory size:
68 # up to 4 GB twice memory size
69 # 4 GB - 8 GB 8 GB
70 # over 8 GB memory size
73 memsize=$(sysctl -n hw.physmem)
76 if [ $memsizeMB -lt 4096 ]
79 elif [ $memsizeMB -lt 8192 ]
86 pagesize=$(sysctl -n hw.pagesize)
87 vm_swap_max=$(($(sysctl -n vm.swap_maxpages) / 2 * $pagesize))
89 if [ $swapmax -gt $vm_swap_max ]
93 echo -n "$swapmax"
96 # Find newly-added swap partition on parent device ($1).
101 $1 == "type:" && $2 == "freebsd-swap" { swapdev = dev }
104 echo -n $swapdev
111 FSTYPE=$(mount -p | awk '{ if ( $2 == "/") { print $3 }}')
112 FSDEV=$(mount -p | awk '{ if ( $2 == "/") { print $1 }}')
119 rootdev=$(zpool list -v $pool | awk 'END { print $1 }')
129 rawdev=$(glabel status | awk -v rootdev=$rootdev 'index(rootdev, $1) { print $3; }')
143 if [ -z "${diskdev}" ]; then
149 # A value of 0 suppresses swap addition,
151 # other values indicate the size in bytes.
152 # If default, check whether swap is already in fstab;
155 swapsize="$(kenv -q growfs_swap_size 2>/dev/null)"
165 $3 == "swap" { exit 1 }
180 [ $verbose -eq 1 ] && {
187 sysctl -b kern.geom.conftxt | awk '
196 size[lvl] = $4
199 disksize = size[lvl]
202 # Do not add swap on disks under 15 GB (decimal) by default.
203 if (addswap == 1 && (size[lvl] > 15000000000 || swapsize > 0))
207 } else if (type[lvl] == "PART" && $11 == "freebsd-swap" && \
209 # This finds swap only if it precedes root, e.g. preceding disk.
212 print "swap device exists, not adding swap"
218 pdev = device[i - 1]
223 # Allow swap if current root is < 40% of disk.
225 (size[i] / disksize < 0.4 || \
227 print "Adding swap partition"
240 # Estimate offset for swap; let
241 # gpart compute actual start and size.
244 if (parttype[i - 1] == "MBR") {
246 print "sz ", size[i - 1], \
247 " off ", offset[i - 1]
248 expand = size[0] - \
249 (size[i - 1] + offset[i - 1])
252 print "sz ", size[i], \
254 expand = size[0] - \
255 (size[i] + offset[i])
259 " sz ", size[i]
260 swapbase = (expand + size[i]) / sector
261 swapbase -= swapsize + align
262 …swapcmd = "gpart add -t freebsd-swap -a " align " -b " int(swapbase) " " pdev " && kenv growfs_swa…
264 swapcmd = "set -x; gpart show; " swapcmd
266 cmd[i] = swapcmd "gpart resize -i " idx[i] " " pdev
286 growfs -y /dev/"$rootdev"
289 zpool online -e $pool $rootdev
293 # Get parent device of swap partition if one was added;
294 # if so, find swap device and label it.
295 pdev=$(kenv -q growfs_swap_pdev)
296 if [ -n "$pdev" ]
299 if [ -z "$dev" ]
301 echo "Swap partition not found on $pdev"
304 glabel label -v growfs_swap $dev