fa6d0df80ee3a7907c1d0399abf1cc2dff445b05
[packages/trusty/cirros-testvm.git] / cirros-testvm / src-cirros / src / bin / growroot
1 #!/bin/sh
2
3 ROOT=${1:-/dev/root}
4
5 fail() { echo "growroot: FAIL:" "$@" 1>&2; exit 1; }
6 msg() { echo "$@"; }
7
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}"
11
12 case "${rootdev}" in
13         *[0-9]) : ;;
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.
16     *) exit 0;;
17 esac
18
19 # remove all consective numbers from the end of rootdev to get 'rootdisk'
20 rootdisk=${rootdev}
21 while [ "${rootdisk%[0-9]}" != "${rootdisk}" ]; do
22         rootdisk=${rootdisk%[0-9]};
23 done
24 partnum=${rootdev#${rootdisk}}
25
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
30
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}")
34 ret=$?
35
36 # if growpart output starts with 'CHANGED:' then it did something.
37 # anything else, exit
38 case "$ret" in
39         0|1) echo "GROWROOT: $out";;
40         *)
41                 echo "$out";
42                 exit $ret;;
43 esac
44
45 # write to /etc/grownroot-grown.
46 { date --utc > "${rootmnt}/etc/growroot-grown" ; } >/dev/null 2>&1 || :
47
48 # vi: ts=4 noexpandtab