From b454618005acaa8248a92905ee5f5086f27c343f Mon Sep 17 00:00:00 2001 From: Kurt J. Bosch Date: Fri, 14 May 2010 11:47:02 +0200 Subject: [PATCH 1/2] Add support for shutdown-time fsck as proposed by Matteo Sasso --- functions | 27 +++++++++++++++++++++++++++ rc.conf | 10 ++++++++++ rc.shutdown | 27 +++++++++++++++++++++++---- rc.sysinit | 38 ++++++++++++-------------------------- 4 files changed, 72 insertions(+), 30 deletions(-) diff --git a/functions b/functions index 672eed2..4847c79 100644 --- a/functions +++ b/functions @@ -2,6 +2,9 @@ # initscripts functions # +# Local filesystem types used for fsck and mount +NETFS="nonfs,nonfs4,nosmbfs,nocifs,nocodafs,noncpfs,nosysfs,noshfs,nofuse,nofuseblk,noglusterfs" + # width: STAT_COL=80 @@ -164,6 +167,26 @@ in_array() { return 1 # Not Found } +# Function for checking filesystems +fsck_all() { + fsckret=0 + if [ -x /sbin/fsck ]; then + stat_busy "Checking Filesystems" + FSCK_OUT=/dev/stdout + FSCK_ERR=/dev/null + FSCK_FD= + run_hook ${0##*rc.}_prefsck + /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 + else + stat_done + fi + run_hook ${0##*rc.}_postfsck + fi +} + # daemons: add_daemon() { @@ -252,6 +275,10 @@ ck_status() { # shutdown_postkillall: after all processes have been killed in rc.shutdown # single_postkillall: after all processes have been killed in rc.single # shutdown_poweroff: directly before powering off in rc.shutdown +# sysinit_prefsck: directly before fsck -A is run in sysinit +# 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 # # Make sure to never override the add_hook and run_hook functions via functions.d 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 187e29e..0460e22 100755 --- a/rc.shutdown +++ b/rc.shutdown @@ -102,6 +102,29 @@ 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 + +fsckret=0 +if [ "$SHUTDOWN_FSCK" = "yes" -o "$SHUTDOWN_FSCK" = "YES" ]; then + FORCEFSCK= + fsck_all +fi + +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 20 +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:" @@ -145,10 +168,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 fd6e970..1611bb0 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -226,28 +226,8 @@ 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 - /bin/mount -n -o remount,ro / - /sbin/reboot -f - 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 *********************" @@ -257,9 +237,7 @@ if [ -x /sbin/fsck ]; then echo "************************************************************" echo /bin/sleep 15 - fsck_reboot - fi - if [ ${fsckret} -gt 1 -a ${fsckret} -ne 32 ]; then + elif [ ${fsckret} -gt 1 -a ${fsckret} -ne 32 ]; then echo echo "***************** FILESYSTEM CHECK FAILED ****************" echo "* *" @@ -272,10 +250,18 @@ if [ -x /sbin/fsck ]; then echo "************************************************************" echo /sbin/sulogin -p - fsck_reboot + else + return fi - stat_done -fi + echo "Automatic reboot in progress..." + /bin/umount -a + /bin/mount -n -o remount,ro / + /sbin/reboot -f + exit 0 +} + +fsck_all +fsck_reboot stat_busy "Mounting Local Filesystems" /bin/mount -n -o remount,rw / -- 1.7.0.3