X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;f=cirros-testvm%2Fsrc-cirros%2Fsrc%2Fbin%2Fgrowroot;fp=cirros-testvm%2Fsrc-cirros%2Fsrc%2Fbin%2Fgrowroot;h=fa6d0df80ee3a7907c1d0399abf1cc2dff445b05;hb=b0a0f15dfaa205161a7fcb20cf1b8cd4948c2ef3;hp=0000000000000000000000000000000000000000;hpb=c6ac3cd55ee2da956195eee393b0882105dfad4e;p=packages%2Ftrusty%2Fcirros-testvm.git diff --git a/cirros-testvm/src-cirros/src/bin/growroot b/cirros-testvm/src-cirros/src/bin/growroot new file mode 100755 index 0000000..fa6d0df --- /dev/null +++ b/cirros-testvm/src-cirros/src/bin/growroot @@ -0,0 +1,48 @@ +#!/bin/sh + +ROOT=${1:-/dev/root} + +fail() { echo "growroot: FAIL:" "$@" 1>&2; exit 1; } +msg() { echo "$@"; } + +# figure out what disk ROOT is on +{ [ ! -L "${ROOT}" ] && rootdev=${ROOT} || rootdev=$(readlink -f "${ROOT}") ; } || + fail "failed to get target of link for ${ROOT}" + +case "${rootdev}" in + *[0-9]) : ;; + # the root is a disk, not a partition (does not end in a digit) + # no need to do anything in this case, kernel already knows the full size. + *) exit 0;; +esac + +# remove all consective numbers from the end of rootdev to get 'rootdisk' +rootdisk=${rootdev} +while [ "${rootdisk%[0-9]}" != "${rootdisk}" ]; do + rootdisk=${rootdisk%[0-9]}; +done +partnum=${rootdev#${rootdisk}} + +# if the basename of the root device (ie 'xvda1' or 'sda1') exists +# in /sys/block/ then it is a block device, not a partition +# (xen xvda1 is an example of such a funny named block device) +[ -e "/sys/block/${rootdev##*/}" ] && exit 0 + +# if growpart fails, exit. its failure messages should go +# to stderr, so they'll get to the console +out=$(growpart "${rootdisk}" "${partnum}") +ret=$? + +# if growpart output starts with 'CHANGED:' then it did something. +# anything else, exit +case "$ret" in + 0|1) echo "GROWROOT: $out";; + *) + echo "$out"; + exit $ret;; +esac + +# write to /etc/grownroot-grown. +{ date --utc > "${rootmnt}/etc/growroot-grown" ; } >/dev/null 2>&1 || : + +# vi: ts=4 noexpandtab