/usr/share/initramfs-tools/scripts/local-premount/rescuevol is in cloud-initramfs-rescuevol 0.25ubuntu1.
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 | #!/bin/sh
RESCUE_LABEL="RESCUE_VOL"
UMOUNT=""
get_dev_by_label() {
local label=${1} dev=""
dev=$(blkid -c /dev/null -w /dev/null -l -o device \
-t "LABEL=${label}") || return 1
[ -n "${dev}" -a -e "${dev}" ] || return 1
_RET=${dev}
}
hasvol() {
local dev="" mp="" label=${1} myinit="${2}"
get_dev_by_label "$label" || return 1
dev=${_RET}
mount -o ro "${dev}" "${MP}" && UMOUNT="${MP}" ||
{ echo "${dev} existed, but mount failed"; return 1; }
mp=${MP}
# the presense of file /etc/rescuevol-ignore in the target indicates
# that we should not use it.
[ -e "${mp}/etc/rescuevol-ignore" ] && {
echo "ignoring rescue volume labeled '${label}' due to /etc/rescuevol-ignore";
return 1;
}
# if /sbin/rescuevol-init exists, then use it rather than /sbin/init
[ -e "${mp}/sbin/rescuevol-init" ] && myinit="/sbin/rescuevol-init"
_RET_DEV=${dev}
_RET_INIT=${myinit}
}
mountfail() {
local vol="" label=${1}
get_dev_by_label "$label" && vol=${_RET}
if [ "${ROOT}" = "${vol}" ]; then
echo "**** Failed to mount rescue volume ${vol} ! *****"
else
cat <<EOF
**** Boot from your root device '${ROOT}' failed! *****
**** You can potentially rescue this instance by attaching *****
**** A volume labeled '${label}' and rebooting. *****
**** If the initramfs sees such a volume, it will attempt *****
**** to boot off of it. *****
EOF
fi
rm "${0}"
exit 1
}
cleanup() {
[ -z "${UMOUNT}" ] || umount "${UMOUNT}"
[ -z "${MP}" -o ! -d "${MP}" ] || rmdir "${MP}"
}
PREREQS=""
case $1 in
prereqs) echo "${PREREQS}"; exit 0;;
esac
. /scripts/functions
# basic setup
MP=/tmp/rescue_mp
mkdir -p "${MP}"
trap cleanup EXIT
[ "$1" = "mountfail" ] && { mountfail "${RESCUE_LABEL}"; exit; }
add_mountroot_fail_hook
hasvol "${RESCUE_LABEL}" "${init:-/sbin/init}" || exit 0
cat > /conf/param.conf <<EOF
init=${_RET_INIT}
ROOT=${_RET_DEV}
EOF
echo "====== Booting RESCUEVOL from ${_RET_DEV} init=${_RET_INIT} ======"
exit 0
# vi: ts=4 noexpandtab
|