This file is indexed.

/usr/share/initramfs-tools/scripts/local-bottom/growroot is in cloud-initramfs-growroot 0.18.debian5.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
#!/bin/sh
set -e

PREREQS=""
case $1 in
    prereqs) echo "${PREREQS}"; exit 0;;
esac

. /scripts/functions

msg() { echo "GROWROOT:" "$@" ; }
fail() { [ $# -eq 0 ] || msg "$@"; exit 1; }

###
### This runs right before exec of /sbin/init. The real root is
### already mounted at rootmnt
###
TEMP_D=""
RESTORE_FROM=""

# if a file indicates we should do nothing, then just exit
for f in /var/lib/cloud/instance/root-grown /etc/growroot-disabled \
	/etc/growroot-grown; do
	[ -f "${rootmnt}$f" ] && exit 0
done

# 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.
# we capture stderr because on success of dry-run, it writes
# to stderr what it would do.
out=$(growpart --dry-run "${rootdisk}" "${partnum}" 2>&1) ||
	{ msg "${out}"; exit 1; }

# if growpart would change something, --dry-run will write something like
#  CHANGE: partition=1 start=2048 old: size=1024000 end=1026048 new: size=2089192,end=2091240
# anything else, exit
case "${out}" in
	CHANGE:*) :;;
	*) exit 0;;
esac

# There was something to do, unmount and resize
umount "${rootmnt}" ||
	fail "failed to umount ${rootmnt}";

# Wait for any of the initial udev events to finish
# This is to avoid any other processes using the block device that the
# root partition is on, which would cause the sfdisk 'BLKRRPART' to fail.
udevadm settle --timeout ${ROOTDELAY:-30} ||
	error "GROWROOT: WARNING: udevadm settle prior to growpart failed"

if out=$(growpart "${rootdisk}" "${partnum}" 2>&1); then
	case "$out" in
		CHANGED:*) echo "GROWROOT: $out";;
    	NOCHANGE:*)
			echo "GROWROOT: WARNING: expected to grow partition, but did not";;
		*) echo "GROWROOT: unexpected output: ${out}"
	esac
else
	echo "GROWROOT: WARNING: resize failed: $out"
fi

# Wait for the partition re-read events to complete 
# so that the root partition is available when we try and mount it.
udevadm settle --timeout ${ROOTDELAY:-30}

# this is taken from 'mountroot' function
#   see /usr/share/initramfs-tools/scripts/local
if [ -z "${ROOTFSTYPE}" ]; then
    FSTYPE=$(get_fstype "${ROOT}")
else
    FSTYPE=${ROOTFSTYPE}
fi
roflag="-r"
[ "${readonly}" = "y" ] || roflag="-w"
mount ${roflag} ${FSTYPE:+-t ${FSTYPE} }${ROOTFLAGS} ${ROOT} ${rootmnt} ||
	fail "failed to re-mount ${ROOT}. this is bad!"

# write to /etc/grownroot-grown. most likely this wont work (readonly)
{ date --utc > "${rootmnt}/etc/growroot-grown" ; } >/dev/null 2>&1 || :

# vi: ts=4 noexpandtab