Package: initramfs-tools Version: 0.120 Severity: normal Allow hooks to supply specific root mount failure handlers. These can both report more specific failure reasons, and in some cases may even be able to attempt recovery. This is useful for more complex scenarios such as LVM and mdadm setups.
We use this in Ubuntu to allow augmented lvm2 and mdadm hooks to recover failed raids and the like. NOTE: that the splash handling here may well be Ubuntu specific. -apw
>From 2f96b329734edeb03d769da83cce1dc06e6c81bb Mon Sep 17 00:00:00 2001 From: Andy Whitcroft <[email protected]> Date: Mon, 25 Jun 2012 12:13:07 +0100 Subject: [PATCH] Add mountroot failure support, to allow meaningful messages when no root device can be found. Signed-off-by: Andy Whitcroft <[email protected]> --- docs/example_script | 13 +++++++++++++ initramfs-tools.8 | 14 ++++++++++++++ scripts/functions | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+) diff --git a/docs/example_script b/docs/example_script index 5e9153b..93d1135 100644 --- a/docs/example_script +++ b/docs/example_script @@ -26,10 +26,23 @@ prereqs) prereqs exit 0 ;; +mountfail) # Called if the script has previously registered a mountroot + # failure. + # Check status, and display any relevant information about the + # failure if there is a problem, then exit with a status of 1. + ;; esac # Do the work here. +# If this script is to be placed in either init-premount, or local-top, +# register a mountroot failure hook, so that further information can be given +# to the user, in the event that the root device cannot be found. + +. /scripts/functions + +add_mountroot_fail_hook + echo "Got here!" exit 0 diff --git a/initramfs-tools.8 b/initramfs-tools.8 index ea8c098..4f873b1 100644 --- a/initramfs-tools.8 +++ b/initramfs-tools.8 @@ -387,6 +387,20 @@ user to investigate the situation. .PP .B Example: panic "Frobnication failed" +.fi +.RE +.RE + +.TP +\fB\fI +add_mountroot_fail_hook +Registers the script as able to provide possible further information, in the +event that the root device cannot be found. See the example script in the +initramfs-tools examples directory for more information. +.RS +.PP +.B Example: +add_mountroot_fail_hook .RE .SS Subdirectories diff --git a/scripts/functions b/scripts/functions index 073fcb3..74083ed 100644 --- a/scripts/functions +++ b/scripts/functions @@ -31,6 +31,42 @@ log_end_msg() _log_msg "done.\n" } +# Add failure hook +add_mountroot_fail_hook() +{ + mkdir -p /tmp/mountroot-fail-hooks.d + ln -s "$0" /tmp/mountroot-fail-hooks.d/"$1" +} + +# Run failure hooks. +# When a failure hook exits "1", it has not done anything to correct the +# system. Exiting "0" means that something has been attempted to resolve +# the lack of a root filesystem. +# Hooks are run in lexigraphical order, and are responsible for removing +# themselves if they should not re-run in a later cycle. When one exits +# "0", the stack is stopped, so the caller can return to the main rootfs +# wait loop. +try_failure_hooks() +{ + local hook + + # Disable usplash so text from hooks can be seen + if [ -x /sbin/usplash_write ]; then + /sbin/usplash_write "QUIT" + fi + chvt 1 + if [ -x /bin/plymouth ] && plymouth --ping; then + /bin/plymouth hide-splash > /dev/null 2>&1 + fi + + for hook in /tmp/mountroot-fail-hooks.d/*; do + if [ -x ${hook} ] && ${hook} mountfail; then + return 0 + fi + done + return 1 +} + panic() { if command -v chvt >/dev/null 2>&1; then -- 2.5.0

