From 17f5715fe72358c01c6bb1e1b7ba6ef833905137 Mon Sep 17 00:00:00 2001 From: Matteo Sasso Date: Thu, 18 Mar 2010 21:00:06 +0100 Subject: [PATCH] Added support for shutdown-time fsck. --- functions | 26 +++++++++++++++++++++ rc.conf | 10 ++++++++ rc.shutdown | 25 +++++++++++++++++--- rc.sysinit | 71 +++++++++++++++++++++++----------------------------------- 4 files changed, 85 insertions(+), 47 deletions(-) diff --git a/functions b/functions index b7b9511..270a4c7 100644 --- a/functions +++ b/functions @@ -164,6 +164,32 @@ in_array() { return 1 # Not Found } + +fsck_all() { + FORCEFSCK= + [ -f /forcefsck ] && FORCEFSCK="-- -f" + NETFS="nonfs,nonfs4,nosmbfs,nocifs,nocodafs,noncpfs,nosysfs,noshfs,nofuse,nofuseblk,noglusterfs" + + if [ -x /sbin/fsck ]; then + stat_busy "Checking Filesystems" + FSCK_OUT=/dev/stdout + FSCK_ERR=/dev/null + FSCK_FD= + run_hook sysinit_prefsck + /sbin/fsck -A -T -C$FSCK_FD -a -t $NETFS $FORCEFSCK >$FSCK_OUT 2>$FSCK_ERR + ret=$? + if [ ${ret} -gt 1 ]; then + stat_fail + else + stat_done + fi + return $ret + else + return 0 + fi +} + + # daemons: add_daemon() { diff --git a/rc.conf b/rc.conf index 252a9b1..15b6a8b 100644 --- a/rc.conf +++ b/rc.conf @@ -91,3 +91,13 @@ ROUTES=(!gateway) # - prefix a daemon with a @ to start it up in the background # DAEMONS=(syslog-ng network netfs crond) + +# ----------------------------------------------------------------------- +# MISCELLANEA +# ----------------------------------------------------------------------- +# +# SHUTDOWN_FSCK: Check all filesystems at shutdown (if needed), +# to make startup time more uniform. +# +SHUTDOWN_FSCK="no" + diff --git a/rc.shutdown b/rc.shutdown index e34d570..7afe8a5 100755 --- a/rc.shutdown +++ b/rc.shutdown @@ -102,6 +102,27 @@ stat_busy "Unmounting Filesystems" /bin/umount -a -r -t noramfs,notmpfs,nosysfs,noproc -O no_netdev stat_done +stat_busy "Remounting Root Filesystem Read-only" +/bin/mount -n -o remount,ro / +stat_done + +if [ "$SHUTDOWN_FSCK" = "yes" -o "$SHUTDOWN_FSCK" = "YES" ]; then + fsck_all + fsckret=$? + if [ ${fsckret} -gt 1 -a ${fsckret} -ne 32 ]; then + echo + echo "***************** FILESYSTEM CHECK FAILED ****************" + echo "* *" + echo "* The filesystem will be checked again on next boot. *" + echo "* If the error persists, you'll be given a chance to fix *" + echo "* the problem manually. *" + echo "* *" + echo "************************************************************" + echo + sleep 20m + fi +fi + # Kill non-root encrypted partition mappings if [ -f /etc/crypttab -a -n "$(/bin/grep -v ^# /etc/crypttab | /bin/grep -v ^$)" ]; then stat_busy "Deactivating encrypted volumes:" @@ -133,10 +154,6 @@ if [ "$USELVM" = "yes" -o "$USELVM" = "YES" ]; then fi fi -stat_busy "Remounting Root Filesystem Read-only" -/bin/mount -n -o remount,ro / -stat_done - run_hook shutdown_poweroff # Power off or reboot diff --git a/rc.sysinit b/rc.sysinit index c4ebd77..a9ca4b7 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -212,10 +212,6 @@ fi status "Mounting Root Read-only" /bin/mount -n -o remount,ro / -FORCEFSCK= -[ -f /forcefsck ] && FORCEFSCK="-- -f" -NETFS="nonfs,nonfs4,nosmbfs,nocifs,nocodafs,noncpfs,nosysfs,noshfs,nofuse,nofuseblk,noglusterfs" - fsck_reboot() { echo "Automatic reboot in progress..." /bin/umount -a @@ -224,45 +220,34 @@ fsck_reboot() { exit 0 } -if [ -x /sbin/fsck ]; then - stat_busy "Checking Filesystems" - FSCK_OUT=/dev/stdout - FSCK_ERR=/dev/null - FSCK_FD= - run_hook sysinit_prefsck - /sbin/fsck -A -T -C$FSCK_FD -a -t $NETFS $FORCEFSCK >$FSCK_OUT 2>$FSCK_ERR - fsckret=$? - if [ ${fsckret} -gt 1 ]; then - stat_fail - fi - run_hook sysinit_postfsck - 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 - stat_done +fsck_all +fsckret=$? +run_hook sysinit_postfsck +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 stat_busy "Mounting Local Filesystems" -- 1.7.0.2