[Pkg-sysvinit-devel] Bug#339850: initscripts: Should check filesystems after an unclean shutdown

Petter Reinholdtsen pere at hungry.com
Sat Nov 19 10:51:25 UTC 2005


Package: initscripts
Version: 2.86.ds1-1
Severity: wishlist
Tags: patch

While reviewing the RedHat boot system, I came across code to detect
unclean shutdowns (aka crashes), and optionally run fsck when booted
after such crashes.

The redhat code will ask during boot, with 5 second timeout to answer,
if an fsck should be forced or not, with the option of setting default
answers to yes or no.  This is the redhat code to enable this (from
/etc/rc.sysinit):

elif [ -f /.autofsck ]; then
        if [ -x /usr/bin/rhgb-client ] && /usr/bin/rhgb-client --ping ; then
             chvt 1
        fi
        echo $"Your system appears to have shut down uncleanly"
        AUTOFSCK_TIMEOUT=5
        [ -f /etc/sysconfig/autofsck ] && . /etc/sysconfig/autofsck
        if [ "$AUTOFSCK_DEF_CHECK" = "yes" ]; then
                AUTOFSCK_OPT=-f
        fi

        if [ "$PROMPT" != "no" ]; then
                if [ "$AUTOFSCK_DEF_CHECK" = "yes" ]; then
                        if /sbin/getkey -c $AUTOFSCK_TIMEOUT -m $"Press N within %
d seconds to not force file system integrity check..." n ; then
                                AUTOFSCK_OPT=
                        fi
                else
                        if /sbin/getkey -c $AUTOFSCK_TIMEOUT -m $"Press Y within %
d seconds to force file system integrity check..." y ; then
                                AUTOFSCK_OPT=-f
                        fi
                fi
                echo
        else
                # PROMPT not allowed
                if [ "$AUTOFSCK_DEF_CHECK" = "yes" ]; then
                        echo $"Forcing file system integrity check due to default
setting"
                else
                        echo $"Not forcing file system integrity check due to defa
ult setting"
                fi
        fi
        fsckoptions="$AUTOFSCK_OPT $fsckoptions"
fi

There is also code to touch the file /.autofsck during boot, and
remove it during shutdown.  Here is a patch to enable something
similar for Debian.  I did not include the large block above, because
/sbin/getkey is missing on Debian as far as I can see.  I am not sure
if we want to use a separate configuration file like
/etc/sysconfig/autofsck for autofsck, or reuse /etc/default/rcS.  We
probably want to store the configuration in /etc/default/rcS, but this
should be discussed.

Here is a patch to implement a naive version of this feature.  It will
always run fsck after a crash, unless /fastboot exist or the laptop is
running on battery.

Index: debian/initscripts/etc/init.d/checkfs.sh
===================================================================
--- debian/initscripts/etc/init.d/checkfs.sh	(revisjon 149)
+++ debian/initscripts/etc/init.d/checkfs.sh	(arbeidskopi)
@@ -39,6 +39,13 @@
         else
             force=""
         fi
+
+	if [ -f /.autofsck ] ; then
+	    log_warning_msg "Your system appears to have shut down uncleanly"
+	    log_warning_msg "Forcing file system check."
+	    force="-f"
+	fi
+
         if [ "$FSCKFIX"  = yes ]
         then
     	fix="-y"
@@ -64,6 +71,10 @@
         fi
     fi
     rm -f /fastboot /forcefsck
+
+    # create the crash indicator flag to warn on crashes, offer fsck
+    # with timeout.
+    touch /.autofsck &> /dev/null
 }
 
 case "$1" in
Index: debian/initscripts/etc/init.d/halt
===================================================================
--- debian/initscripts/etc/init.d/halt	(revisjon 149)
+++ debian/initscripts/etc/init.d/halt	(arbeidskopi)
@@ -56,6 +56,9 @@
 		poweroff=""
 	fi
 
+	# Remove unclean shutdown flag
+	rm -f /.autofsck
+
 	log_action_msg "Will now halt"
 	halt -d -f -i $poweroff $hddown
 }
Index: debian/initscripts/etc/init.d/reboot
===================================================================
--- debian/initscripts/etc/init.d/reboot	(revisjon 149)
+++ debian/initscripts/etc/init.d/reboot	(arbeidskopi)
@@ -17,6 +17,9 @@
 . /lib/lsb/init-functions
 
 do_stop () {
+	# Remove unclean shutdown flag
+	rm -f /.autofsck
+
 	log_action_msg "Will now reboot"
 	reboot -d -f -i
 }




More information about the Pkg-sysvinit-devel mailing list