[arch-projects] [PATCH 0/4] Move fsck/mount into functions (FS#18736)
This allows some customization like doing fsck at shutdown, on loop etc. Kurt J. Bosch (4): Move fsck stuff into functions to allow custom overrides (FS#18736) Simplify fsck functions Allow custom fsck on shutdown via hook (FS#18736) Move mount -a into functions to allow custom override (fsck on loop) functions | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ rc.shutdown | 2 + rc.sysinit | 60 +++-------------------------------------------------- 3 files changed, 71 insertions(+), 56 deletions(-)
--- functions | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ rc.sysinit | 51 ++------------------------------------------------- 2 files changed, 60 insertions(+), 49 deletions(-) diff --git a/functions b/functions index d0747ba..a5d87dc 100644 --- a/functions +++ b/functions @@ -316,6 +316,64 @@ read_crypttab() { return $failed } +fsck_all() { + stat_busy "Checking Filesystems" + FSCK_OUT=/dev/stdout + FSCK_ERR=/dev/stdout + FSCK_FD= + FORCEFSCK= + [[ -f /forcefsck ]] && FORCEFSCK="-- -f" + local cmdarg + for cmdarg in $(< /proc/cmdline); do + [[ "$cmdarg" == forcefsck ]] && FORCEFSCK="-- -f" && break + done + run_hook sysinit_prefsck + fsck -A -T -C$FSCK_FD -a -t "$NETFS,noopts=_netdev" $FORCEFSCK >$FSCK_OUT 2>$FSCK_ERR + local fsckret=$? + if ((fsckret > 1)); then + stat_fail + else + stat_done + fi + run_hook sysinit_postfsck + return $fsckret +} + +fsck_reboot() { + # $1 = exit code returned by fsck + local fsckret=$1 + if (( ( fsckret & 2) == 2)); then + echo + echo "********************** REBOOT REQUIRED *********************" + echo "* *" + echo "* The system will be rebooted automatically in 15 seconds. *" + echo "* *" + echo "************************************************************" + echo + sleep 15 + elif ((fsckret > 1 && fsckret != 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 + sulogin -p + else + return + fi + echo "Automatic reboot in progress..." + umount -a + mount -n -o remount,ro / + reboot -f + exit 0 +} + ############################### # Custom hooks in initscripts # ############################### diff --git a/rc.sysinit b/rc.sysinit index b5d63ea..e08adc6 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -214,55 +214,8 @@ fi NETFS="nonfs,nonfs4,nosmbfs,nocifs,nocodafs,noncpfs,nosysfs,noshfs,nofuse,nofuseblk,noglusterfs,nodavfs" if [[ -x $(type -P fsck) ]]; then - stat_busy "Checking Filesystems" - fsck_reboot() { - echo "Automatic reboot in progress..." - umount -a - mount -n -o remount,ro / - reboot -f - exit 0 - } - FSCK_OUT=/dev/stdout - FSCK_ERR=/dev/stdout - FSCK_FD= - FORCEFSCK= - [[ -f /forcefsck ]] && FORCEFSCK="-- -f" - for cmdarg in $(< /proc/cmdline); do - [[ "$cmdarg" == forcefsck ]] && FORCEFSCK="-- -f" && break - done - run_hook sysinit_prefsck - fsck -A -T -C$FSCK_FD -a -t "$NETFS,noopts=_netdev" $FORCEFSCK >$FSCK_OUT 2>$FSCK_ERR - fsckret=$? - if ((fsckret > 1)); then - stat_fail - fi - run_hook sysinit_postfsck - if (( ( fsckret & 2) == 2)); then - echo - echo "********************** REBOOT REQUIRED *********************" - echo "* *" - echo "* The system will be rebooted automatically in 15 seconds. *" - echo "* *" - echo "************************************************************" - echo - sleep 15 - fsck_reboot - elif ((fsckret > 1 && fsckret != 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 - sulogin -p - fsck_reboot - fi - stat_done + fsck_all + fsck_reboot $? fi stat_busy "Mounting Local Filesystems" -- 1.7.1
--- functions | 16 ++++++---------- 1 files changed, 6 insertions(+), 10 deletions(-) diff --git a/functions b/functions index a5d87dc..9b6f695 100644 --- a/functions +++ b/functions @@ -322,11 +322,7 @@ fsck_all() { FSCK_ERR=/dev/stdout FSCK_FD= FORCEFSCK= - [[ -f /forcefsck ]] && FORCEFSCK="-- -f" - local cmdarg - for cmdarg in $(< /proc/cmdline); do - [[ "$cmdarg" == forcefsck ]] && FORCEFSCK="-- -f" && break - done + [[ -f /forcefsck ]] || in_array forcefsck $(< /proc/cmdline) && FORCEFSCK="-- -f" run_hook sysinit_prefsck fsck -A -T -C$FSCK_FD -a -t "$NETFS,noopts=_netdev" $FORCEFSCK >$FSCK_OUT 2>$FSCK_ERR local fsckret=$? @@ -341,8 +337,10 @@ fsck_all() { fsck_reboot() { # $1 = exit code returned by fsck - local fsckret=$1 - if (( ( fsckret & 2) == 2)); then + # Ignore conditions 'FS errors corrected' and 'Cancelled by the user' + if (( ($1 | 33) == 33 )); then + return 0 + elif (($1 & 2)); then echo echo "********************** REBOOT REQUIRED *********************" echo "* *" @@ -351,7 +349,7 @@ fsck_reboot() { echo "************************************************************" echo sleep 15 - elif ((fsckret > 1 && fsckret != 32)); then + else echo echo "***************** FILESYSTEM CHECK FAILED ****************" echo "* *" @@ -364,8 +362,6 @@ fsck_reboot() { echo "************************************************************" echo sulogin -p - else - return fi echo "Automatic reboot in progress..." umount -a -- 1.7.1
--- functions | 3 +++ rc.shutdown | 2 ++ rc.sysinit | 2 -- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/functions b/functions index 9b6f695..a02bd3b 100644 --- a/functions +++ b/functions @@ -316,6 +316,8 @@ read_crypttab() { return $failed } +NETFS="nonfs,nonfs4,nosmbfs,nocifs,nocodafs,noncpfs,nosysfs,noshfs,nofuse,nofuseblk,noglusterfs,nodavfs" + fsck_all() { stat_busy "Checking Filesystems" FSCK_OUT=/dev/stdout @@ -401,6 +403,7 @@ fsck_reboot() { # single_prekillall: before all processes are being killed in rc.single # shutdown_postkillall: after all processes have been killed in rc.shutdown # single_postkillall: after all processes have been killed in rc.single +# shutdown_postumount: after filesystems are unmounted # shutdown_poweroff: directly before powering off in rc.shutdown # # Declare add_hook and run_hook as read-only to prevent overwriting them. diff --git a/rc.shutdown b/rc.shutdown index fc12958..637974f 100755 --- a/rc.shutdown +++ b/rc.shutdown @@ -61,6 +61,8 @@ else fi stat_done +run_hook shutdown_postumount + # Kill non-root encrypted partition mappings if [[ -f /etc/crypttab && -n $CS ]] && grep -q ^[^#] /etc/crypttab; then stat_busy "Deactivating encrypted volumes:" diff --git a/rc.sysinit b/rc.sysinit index e08adc6..5af74a1 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -211,8 +211,6 @@ if [[ -f /etc/crypttab && -n $CS ]] && grep -q ^[^#] /etc/crypttab; then fi fi -NETFS="nonfs,nonfs4,nosmbfs,nocifs,nocodafs,noncpfs,nosysfs,noshfs,nofuse,nofuseblk,noglusterfs,nodavfs" - if [[ -x $(type -P fsck) ]]; then fsck_all fsck_reboot $? -- 1.7.1
--- functions | 8 ++++++++ rc.sysinit | 7 ++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/functions b/functions index a02bd3b..f4435b1 100644 --- a/functions +++ b/functions @@ -372,6 +372,14 @@ fsck_reboot() { exit 0 } +mount_all() { + stat_busy "Mounting Local Filesystems" + run_hook sysinit_premount + mount -a -t $NETFS -O no_netdev + run_hook sysinit_postmount + stat_done +} + ############################### # Custom hooks in initscripts # ############################### diff --git a/rc.sysinit b/rc.sysinit index 5af74a1..7bcd0a5 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -216,7 +216,7 @@ if [[ -x $(type -P fsck) ]]; then fsck_reboot $? fi -stat_busy "Mounting Local Filesystems" +status "Remounting Root Read/Write" \ mount -n -o remount,rw / # don't touch /etc/mtab if it is a symlink to /proc/self/mounts @@ -228,11 +228,8 @@ stat_busy "Mounting Local Filesystems" cat /proc/mounts >| /etc/mtab fi - run_hook sysinit_premount # now mount all the local filesystems - mount -a -t $NETFS -O no_netdev - run_hook sysinit_postmount -stat_done +mount_all # enable monitoring of lvm2 groups, now that the filesystems are mounted rw if [[ $USELVM = [Yy][Ee][Ss] && -x $(type -P lvm) && -d /sys/block ]]; then -- 1.7.1
Thanks Kurt, Ill review as soon as i get the chance. -t On Wed, Jun 22, 2011 at 12:07 PM, Kurt J. Bosch <kjb-temp-2009@alpenjodel.de> wrote:
This allows some customization like doing fsck at shutdown, on loop etc.
Kurt J. Bosch (4): Move fsck stuff into functions to allow custom overrides (FS#18736) Simplify fsck functions Allow custom fsck on shutdown via hook (FS#18736) Move mount -a into functions to allow custom override (fsck on loop)
functions | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ rc.shutdown | 2 + rc.sysinit | 60 +++-------------------------------------------------- 3 files changed, 71 insertions(+), 56 deletions(-)
Hi Kurt, On Wednesday 22 June 2011 12:07:42 Kurt J. Bosch wrote:
This allows some customization like doing fsck at shutdown, on loop etc.
I was not able to apply your patches. Could you tell me which commit they should be on top of, or (preferable) point me to your public git repo? Cheers, Tom
On Wednesday 22 June 2011 23:00:58 you wrote:
Hi Kurt,
On Wednesday 22 June 2011 12:07:42 Kurt J. Bosch wrote:
This allows some customization like doing fsck at shutdown, on loop etc.
I was not able to apply your patches. Could you tell me which commit they should be on top of, or (preferable) point me to your public git repo?
Nevermind, my git-am magic was messing up the order of the patches. Reordeing fixed it. -t
participants (2)
-
Kurt J. Bosch
-
Tom Gundersen