From 0468406d1e70c1ab0f47a7f565bdb16f3282c427 Mon Sep 17 00:00:00 2001 From: Kurt J. Bosch Date: Fri, 19 Mar 2010 19:08:23 +0100 Subject: [PATCH 3/3] Support fsck on loop filesystems (sysinit by now) --- functions | 25 +++++++++++++++++++++- rc.sysinit | 63 ++++++++++++++++++++++++++++++++++------------------------- 2 files changed, 59 insertions(+), 29 deletions(-) diff --git a/functions b/functions index b6a40d9..26bce39 100644 --- a/functions +++ b/functions @@ -167,7 +167,7 @@ in_array() { return 1 # Not Found } -# Function for checking filesystems +# Functions for checking filesystems fsck_all() { fsckret=0 if [ -x /sbin/fsck ]; then @@ -176,7 +176,7 @@ fsck_all() { FSCK_ERR=/dev/null FSCK_FD= run_hook ${0##*rc.}_prefsck - /sbin/fsck -A -T -C$FSCK_FD -a -t $NETFS $FORCEFSCK >$FSCK_OUT 2>$FSCK_ERR + /sbin/fsck -A -T -C$FSCK_FD -a -t $NETFS,noopts=loop $FORCEFSCK >$FSCK_OUT 2>$FSCK_ERR fsckret=$? if [ ${fsckret} -gt 1 ]; then stat_fail @@ -187,6 +187,25 @@ fsck_all() { fi } +fsck_loop() { + fsckret=0 + if [ -x /sbin/fsck ]; then + stat_busy "Checking Loop Filesystems" + FSCK_OUT=/dev/stdout + FSCK_ERR=/dev/null + FSCK_FD= + run_hook ${0##*rc.}_prefsckloop + /sbin/fsck -A -T -C$FSCK_FD -a -t $NETFS,opts=loop $FORCEFSCK >$FSCK_OUT 2>$FSCK_ERR + fsckret=$? + if [ ${fsckret} -gt 1 ]; then + stat_fail + else + stat_done + fi + run_hook ${0##*rc.}_postfsckloop + fi +} + # daemons: add_daemon() { @@ -279,6 +298,8 @@ ck_status() { # shutdown_prefsck: directly before fsck -A is run in shutdown # sysinit_postfsck: after fsck -A was run in sysinit # shutdown_postfsck after fsck -A was run in shutdown +# sysinit_prefsckloop: directly before fsck -A is run on loop filesystems in sysinit +# sysinit_postfsckloop: after fsck -A was run on loop filesystems in sysinit # # Make sure to never override the add_hook and run_hook functions via functions.d diff --git a/rc.sysinit b/rc.sysinit index bab5db9..7c608db 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -213,6 +213,32 @@ fi status "Mounting Root Read-only" /bin/mount -n -o remount,ro / fsck_reboot() { + if [ ${fsckret} -eq 0 -o ${fsckret} -eq 32 ]; then + return + fi + if [ $((${fsckret}&2)) -eq 2 ]; then + echo + echo "********************** REBOOT REQUIRED *********************" + echo "* *" + echo "* The system will be rebooted automatically in 15 seconds. *" + echo "* *" + echo "************************************************************" + echo + /bin/sleep 15 + else + echo + echo "***************** FILESYSTEM CHECK FAILED ****************" + echo "* *" + echo "* Please repair manually and reboot. Note that the root *" + echo "* file system might be mounted read-only. To remount it *" + echo "* read-write type: mount -n -o remount,rw / *" + echo "* When you exit the maintenance shell the system will *" + echo "* reboot automatically. *" + echo "* *" + echo "************************************************************" + echo + /sbin/sulogin -p + fi echo "Automatic reboot in progress..." /bin/umount -a /bin/mount -n -o remount,ro / @@ -222,33 +248,9 @@ fsck_reboot() { FORCEFSCK= [ -f /forcefsck ] && FORCEFSCK="-- -f" + fsck_all -if [ $((${fsckret}&2)) -eq 2 ]; then - echo - echo "********************** REBOOT REQUIRED *********************" - echo "* *" - echo "* The system will be rebooted automatically in 15 seconds. *" - echo "* *" - echo "************************************************************" - echo - /bin/sleep 15 - fsck_reboot -fi -if [ ${fsckret} -gt 1 -a ${fsckret} -ne 32 ]; then - echo - echo "***************** FILESYSTEM CHECK FAILED ****************" - echo "* *" - echo "* Please repair manually and reboot. Note that the root *" - echo "* file system is currently mounted read-only. To remount *" - echo "* it read-write type: mount -n -o remount,rw / *" - echo "* When you exit the maintenance shell the system will *" - echo "* reboot automatically. *" - echo "* *" - echo "************************************************************" - echo - /sbin/sulogin -p - fsck_reboot -fi +fsck_reboot stat_busy "Mounting Local Filesystems" /bin/mount -n -o remount,rw / @@ -261,7 +263,14 @@ if [ -e /proc/mounts ]; then fi run_hook sysinit_premount # now mount all the local filesystems -/bin/mount -a -t $NETFS -O no_netdev +/bin/mount -a -t $NETFS -O no_netdev,noloop +stat_done + +fsck_loop +fsck_reboot + +stat_busy "Mounting Local Loop Filesystems" +/bin/mount -a -t $NETFS -O no_netdev,loop stat_done status "Activating Swap" /sbin/swapon -a -- 1.7.0.2