Permalink
Browse files

Teach /etc/rc.d/growfs how to handle systems running ZFS.

There are many cases which this code does not handle (e.g. ZFS mirrors)
but the code can handle the single-disk case -- so it's enough to take
care of the "disk image which gets booted into a VM with a larger than
expected disk" case for which this firstboot script was created.

MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D19095
  • Loading branch information...
cperciva committed Feb 8, 2019
1 parent 8eb3289 commit 67d22017865a805ac7413b8fd8bbf9d1c743ee47
Showing with 22 additions and 2 deletions.
  1. +22 −2 libexec/rc/rc.d/growfs
@@ -49,7 +49,20 @@ rcvar="growfs_enable"
growfs_start ()
{
echo "Growing root partition to fill device"
rootdev=$(df / | tail -n 1 | awk '{ sub("/dev/", "", $1); print $1 }')
FSTYPE=$(mount -p | awk '{ if ( $2 == "/") { print $3 }}')
FSDEV=$(mount -p | awk '{ if ( $2 == "/") { print $1 }}')
case "$FSTYPE" in
ufs)
rootdev=${FSDEV#/dev/}
;;
zfs)
pool=${FSDEV%%/*}
rootdev=$(zpool list -v $pool | tail -n 1 | awk '{ print $1 }')
;;
*)
echo "Don't know how to grow root filesystem type: $FSTYPE"
return
esac
if [ x"$rootdev" = x"${rootdev%/*}" ]; then
# raw device
rawdev="$rootdev"
@@ -91,7 +104,14 @@ growfs_start ()
}
}' dev="$rawdev"
gpart commit "$rootdev"
growfs -y /dev/"$rootdev"
case "$FSTYPE" in
ufs)
growfs -y /dev/"$rootdev"
;;
zfs)
zpool online -e $pool $rootdev
;;
esac
}

load_rc_config $name

0 comments on commit 67d2201

Please sign in to comment.