5 fail() { echo "growroot: FAIL:" "$@" 1>&2; exit 1; }
8 # figure out what disk ROOT is on
9 { [ ! -L "${ROOT}" ] && rootdev=${ROOT} || rootdev=$(readlink -f "${ROOT}") ; } ||
10 fail "failed to get target of link for ${ROOT}"
14 # the root is a disk, not a partition (does not end in a digit)
15 # no need to do anything in this case, kernel already knows the full size.
19 # remove all consective numbers from the end of rootdev to get 'rootdisk'
21 while [ "${rootdisk%[0-9]}" != "${rootdisk}" ]; do
22 rootdisk=${rootdisk%[0-9]};
24 partnum=${rootdev#${rootdisk}}
26 # if the basename of the root device (ie 'xvda1' or 'sda1') exists
27 # in /sys/block/ then it is a block device, not a partition
28 # (xen xvda1 is an example of such a funny named block device)
29 [ -e "/sys/block/${rootdev##*/}" ] && exit 0
31 # if growpart fails, exit. its failure messages should go
32 # to stderr, so they'll get to the console
33 out=$(growpart "${rootdisk}" "${partnum}")
36 # if growpart output starts with 'CHANGED:' then it did something.
39 0|1) echo "GROWROOT: $out";;
45 # write to /etc/grownroot-grown.
46 { date --utc > "${rootmnt}/etc/growroot-grown" ; } >/dev/null 2>&1 || :
48 # vi: ts=4 noexpandtab