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

Re: Fragen zu fsck beim Booten



Hallo Thomas!

Thomas Kosch schrieb am Mittwoch, den 01. April 2009:

>
> Hast du dir checkfs.sh und checkroot.sh mal angesehen? Das von dir  
> angedachte da reinzuhacken ohne das da unter Umständen unangenehme  
> Seitenwirkungen auftreten dürfte nicht ganz trivial sein.
>

Ich hab jetzt mal einen experimentellen Patch¹ gegen checkfs.sh und 
checkroot.sh erstellt. Ich konnte den patch nur sehr begrenzt testen², 
da ich hier aktuell nur eine VM zur Verfügung habe und kein richtiges 
System mit mehreren Devices.

Zur Anwendung:
Als root ins /etc/init.d Verzeichnis wechseln.
patch -p1 < patchfile
und dann /etc/init.d/chkfshalt.sh nach /etc/rc0.d/S65chkfshalt 
verlinken. Das chkfshalt Script sollte als letztes vor S90halt 
ausgeführt werden, also eine Nummer wählen, die entsrpechend hoch ist, 
aber kleiner als der halt link.

Die Grundidee ist, dass wenn checkfs.sh einen Dateisystemcheck 
durchführen möchte, der Aufruf in /fsck_halt gespeichert wird und 
diese Datei beim runterfahren ausgeführt wird. Dummerweise, kann man 
dann die Datei nicht mehr löschen und auch kein Log mehr anlegen, weil 
bereits alle Dateisysteme ausgehängt worden. Daher wird die Datei dann 
nach dem einhängen des root-devices gelöscht (chkroot.sh). In 
chkroot.sh wird außerdem grundsätzlich auf den Dateisystemcheck 
verzichtet. Durch setzen der Variable CHECK_ON_HALT in den beiden 
Scripten kann man das alte Verhalten wieder herstellen. (oder durch 
rückgängig machen des Patches).

Wer möchte kann es ja mal testen. Ich übernehme keine Verantwortung.

> Die Chance dir dabei in den Fuß zu schießen ist relativ hoch. Ich 
> wollte nur wissen was du dabei bevorzugst.

No risk, no fun ;)

Grüße
Christian
__
¹) Ich habe den Patch auf einem nicht ganz aktuellen testing/sid 
System erstellt. Es könnte also sein, dass er nicht passt.
²) Ich halte diese Funktionalität eigentlich auch nicht für sonderlich 
sinnvoll.
-- 
hundred-and-one symptoms of being an internet addict:
176. You lie, even to user-friends, about how long you were online yesterday.
diff -Nur init.d/checkfs.sh init.d.new/checkfs.sh
--- init.d/checkfs.sh	2008-08-12 14:50:47.000000000 +0200
+++ init.d.new/checkfs.sh	2009-04-01 23:03:41.000000000 +0200
@@ -19,6 +19,8 @@
 . /lib/lsb/init-functions
 . /lib/init/splash-functions-base
 
+CHECK_ON_HALT=yes
+
 do_start () {
 	# See if we're on AC Power.  If not, we're not gonna run our
 	# check.  If on_ac_power (in /usr/) is unavailable, behave as
@@ -77,14 +79,19 @@
 		if [ "$VERBOSE" = no ]
 		then
 			log_action_begin_msg "Checking file systems"
-			logsave -s $FSCK_LOGFILE fsck $spinner -R -A $fix $force $FSCKTYPES_OPT
-			FSCKCODE=$?
-			if [ "$FSCKCODE" -gt 1 ]
+			if [ "$CHECK_ON_HALT" = "yes" ]
 			then
-				log_action_end_msg 1 "code $FSCKCODE"
-				handle_failed_fsck
+			    echo "fsck $spinner -R -A $fix $force $FSCKTYPES_OPT" >/fsck_halt
 			else
-				log_action_end_msg 0
+			    logsave -s $FSCK_LOGFILE fsck $spinner -R -A $fix $force $FSCKTYPES_OPT
+			    FSCKCODE=$?
+			    if [ "$FSCKCODE" -gt 1 ]
+			    then
+				    log_action_end_msg 1 "code $FSCKCODE"
+				    handle_failed_fsck
+			    else
+				    log_action_end_msg 0
+			    fi
 			fi
 		else
 			if [ "$FSCKTYPES" ]
@@ -93,14 +100,19 @@
 			else
 				log_action_msg "Will now check all file systems"
 			fi
-			logsave -s $FSCK_LOGFILE fsck $spinner -V -R -A $fix $force $FSCKTYPES_OPT
-			FSCKCODE=$?
-			if [ "$FSCKCODE" -gt 1 ]
+			if [ "$CHECK_ON_HALT" = "yes" ]
 			then
-				handle_failed_fsck
+			    echo "fsck $spinner -V -R -A $fix $force $FSCKTYPES_OPT" > /fsck_halt
 			else
-				log_success_msg "Done checking file systems. 
-A log is being saved in ${FSCK_LOGFILE} if that location is writable."
+			    logsave -s $FSCK_LOGFILE fsck $spinner -V -R -A $fix $force $FSCKTYPES_OPT
+			    FSCKCODE=$?
+			    if [ "$FSCKCODE" -gt 1 ]
+			    then
+				    handle_failed_fsck
+			    else
+				    log_success_msg "Done checking file systems. 
+    A log is being saved in ${FSCK_LOGFILE} if that location is writable."
+			    fi
 			fi
 		fi
 		splash_stop_indefinite
diff -Nur init.d/checkroot.sh init.d.new/checkroot.sh
--- init.d/checkroot.sh	2007-12-30 16:45:44.000000000 +0100
+++ init.d.new/checkroot.sh	2009-04-01 23:02:48.000000000 +0200
@@ -22,6 +22,8 @@
 . /lib/init/mount-functions.sh
 . /lib/init/splash-functions-base
 
+CHECK_ON_HALT=yes
+
 do_start () {
 	#
 	# Set SULOGIN in /etc/default/rcS to yes if you want a sulogin to
@@ -206,7 +208,7 @@
 	# See if we want to check the root file system.
 	#
 	FSCKCODE=0
-	if [ -f /fastboot ]
+	if [ -f /fastboot -o "$CHECK_ON_HALT" = "yes" ]
 	then
 		[ "$rootcheck" = yes ] && log_warning_msg "Fast boot enabled, so skipping file system check."
 		rootcheck=no
@@ -380,7 +382,7 @@
 	#
 	# Remove /lib/init/rw/rootdev if we created it.
 	#
-	rm -f /lib/init/rw/rootdev
+	rm -f /lib/init/rw/rootdev /fsck_halt
 }
 
 case "$1" in
diff -Nur init.d/chkfshalt.sh init.d.new/chkfshalt.sh
--- init.d/chkfshalt.sh	1970-01-01 01:00:00.000000000 +0100
+++ init.d.new/chkfshalt.sh	2009-04-01 23:17:03.000000000 +0200
@@ -0,0 +1,51 @@
+#! /bin/sh
+### BEGIN INIT INFO
+# Provides:          checkfshalt
+# Required-Start:    
+# Required-Stop:     umountroot
+# Should-Start:      
+# Default-Start:     S
+# Default-Stop:
+# Short-Description: Check all filesystems on halt.
+### END INIT INFO
+
+# Include /usr/bin in path to find on_ac_power if /usr/ is on the root
+# partition.
+PATH=/sbin:/bin:/usr/bin
+FSCK_LOGFILE=/var/log/fsck/checkfs
+[ "$FSCKFIX" ] || FSCKFIX=no
+. /lib/init/vars.sh
+
+. /lib/lsb/init-functions
+. /lib/init/splash-functions-base
+
+CHECK_ON_HALT=yes
+
+do_stop () {
+    if [ -f /fsck_halt ]
+    then
+        echo "Checking Filesystem"
+	. /fsck_halt
+	echo "Done checking"
+	read
+    fi
+}
+
+case "$1" in
+  start|"")
+	# No-op
+	;;
+  restart|reload|force-reload)
+	echo "Error: argument '$1' not supported" >&2
+	exit 3
+	;;
+  stop)
+	do_stop
+	;;
+  *)
+	echo "Usage: checkfs.sh [start|stop]" >&2
+	exit 3
+	;;
+esac
+
+:

Reply to: