[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[PATCH initramfs-tools 2/3] checkfs: Correct error messages and emergency shell in case of failure



The current error messages and some code are taken from initscripts,
which will fsck an already-mounted root filesystem and then must
reboot if it is modified.  Here we have not mounted the filesystem and
can continue if the fsck was successful, or retry after running an
emergency shell.

The emergency shell also doesn't work (sulogin crashes); we must use
the panic function for this instead.

log_warning_msg does not print to the console if the 'quiet' parameter
was used, so is not suitable for warning messages that must appear
unconditionally.  Pass a terse explanatory message to the panic
function.

Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
 scripts/functions | 33 +++++++++++----------------------
 1 file changed, 11 insertions(+), 22 deletions(-)

diff --git a/scripts/functions b/scripts/functions
index 398c822..8f9f0ba 100644
--- a/scripts/functions
+++ b/scripts/functions
@@ -332,7 +332,7 @@ resolve_device() {
 # Check a file system.
 # $1=device
 # $2=mountpoint (for diagnostics only)
-checkfs()
+_checkfs_once()
 {
 	DEV="$1"
 	NAME="$2"
@@ -392,32 +392,21 @@ checkfs()
 		log_warning_msg "File system check was interrupted by user"
 	elif [ $((FSCKCODE & 4)) -eq 4 ]
 	then
-		# Surprise! Re-directing from a HERE document (as in "cat << EOF")
-		# does not work because the fs is currently read-only.
-		log_failure_msg "An automatic file system check (fsck) of the $NAME filesystem failed.
-A manual fsck must be performed, then the system restarted.
-The fsck should be performed in maintenance mode with the
-$NAME filesystem mounted in read-only mode."
-		log_warning_msg "The $NAME filesystem is currently mounted in read-only mode.
-A maintenance shell will now be started.
-After performing system maintenance, press CONTROL-D
-to terminate the maintenance shell and restart the system."
-		# Start a single user shell on the console
-		if ! sulogin $CONSOLE
-		then
-			log_failure_msg "Attempt to start maintenance shell failed.
-Will restart in 5 seconds."
-			sleep 5
-		fi
-		if [ "${verbose}" = "y" ] ; then
-			log_begin_msg "Will now restart"
-		fi
-		reboot
+		log_failure_msg "File system check of the $NAME filesystem failed"
+		return 1
 	elif [ "$FSCKCODE" -gt 1 ]
 	then
 		log_warning_msg "File system check failed but did not detect errors"
 		sleep 5
 	fi
+	return 0
+}
+
+checkfs()
+{
+	while ! _checkfs_once "$@"; do
+		panic "The $2 filesystem on $1 requires a manual fsck"
+	done
 }
 
 # Mount a file system.  We parse the information from the fstab.  This


-- 
Ben Hutchings
The first rule of tautology club is the first rule of tautology club.

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


Reply to: