Bug#795833: initramfs-tools: add mountroot failure support to allow meaningful messages and recovery attempts

2016-01-25 Thread Ben Hutchings
On Wed, 2015-12-09 at 16:05 +, Ben Hutchings wrote:
> On Mon, 17 Aug 2015 10:52:14 +0100 Andy Whitcroft  wrote:
> > 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.
> 
> Thanks for your patch.
> 
> Can you explain why this was implemented by extending existing scripts
> rather than by adding a new phase (possibly with stamp files to control
> what they do)?
[...]

I do need some justification of this change.

Also, could we have a meeting (IRC or irl) at some point about the
remaining differences between the Debian/upstream and Ubuntu packages,
and how to resolve them?

Ben.

-- 
Ben Hutchings
Klipstein's 4th Law of Prototyping and Production:
A fail-safe circuit will destroy others.

signature.asc
Description: This is a digitally signed message part


Bug#795833: initramfs-tools: add mountroot failure support to allow meaningful messages and recovery attempts

2015-12-09 Thread Ben Hutchings
On Mon, 17 Aug 2015 10:52:14 +0100 Andy Whitcroft  wrote:
> 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.

Thanks for your patch.

Can you explain why this was implemented by extending existing scripts
rather than by adding a new phase (possibly with stamp files to control
what they do)?

[...]
> --- a/scripts/functions
> +++ b/scripts/functions
[...]
> +# 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.

'Hook' is reserved for build-time scripts, so use 'script' here.

> +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
[...]

This bit can be handled by 'panic' scripts once #602331 is fixed
(currently pending).

Ben.

-- 
Ben Hutchings
I'm always amazed by the number of people who take up solipsism because
they heard someone else explain it. - E*Borg on alt.fan.pratchett

signature.asc
Description: This is a digitally signed message part


Bug#795833: initramfs-tools: add mountroot failure support to allow meaningful messages and recovery attempts

2015-08-17 Thread Andy Whitcroft
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 a...@canonical.com
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 a...@ubuntu.com
---
 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 21
+	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 21; then
-- 
2.5.0