LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (http://www.linuxquestions.org/questions/slackware-14/)
-   -   large partition fsck on shutdown instead of boot (http://www.linuxquestions.org/questions/slackware-14/large-partition-fsck-on-shutdown-instead-of-boot-832243/)

lazardo 09-15-2010 03:22 AM

large partition fsck on shutdown instead of boot
 
Got tired of long waits for fsck on very large partitions.

Here's a script to fsck selected partitions every 'N' shutdowns. No more boot delays for fsck (unless something is really wrong ;)

Cheers,

Update1: On my system '/usr/libexec/gam_server' (gamin component used by xfce) prevented /home from being unmounted. I changed
Code:

DISK=/dev/mapper/home; MAX_MCOUNT=1; diskchk
to
Code:

DISK=/dev/mapper/home; MAX_MCOUNT=1; pkill -f gam_server; diskchk
and now my cryptsetup/LUKS home directory gets fscked on shutdown.

Update2: Patch to enhance partition unmount logic.

Code:

--- rc.local_shutdown            2010-09-21 12:12:53.000000000 -0700
+++ rc.local_shutdown.0.4        2010-09-21 12:20:36.000000000 -0700
@@ -3,6 +3,7 @@
 # Manage large, non-system, ext2/3/4 filesystem checks at
 # shutdown rather than boot.  Tested with Slackware 13.1
 
+# ver 0.4.final: /proc/mounts check
 # ver 0.3.final, em dot lazardo at gmail
 
 function message () {
@@ -16,16 +17,21 @@
        message "$DISK mount count = ${CUR_MCOUNT[2]}/$MAX_MCOUNT"
 
        if [ ${CUR_MCOUNT[2]} -gt $MAX_MCOUNT ]; then
-                umount -v $DISK
-                if [ $? -ne 0 ]; then
-                        message "cant unmount $DISK (fuser: `fuser -c $DISK`)"
-                else
-                        message "starting $DISK fsck"
-                        ( fsck -yfC $DISK; message "finished $DISK fsck" ) &
-
-                        PID[$cnt]=$!
-                        ((cnt++))
+                grep -q $DISK /proc/mounts
+                if [ $? -eq 0 ]; then
+                        umount -v $DISK
+                        if [ $? -ne 0 ]; then
+                                message "cant unmount $DISK (fuser: `fuser -c $DISK`)"
+                                sleep 5
+                                return
+                        fi
                fi
+
+                message "starting $DISK fsck"
+                ( fsck -yfC $DISK; message "finished $DISK fsck" ) &
+
+                PID[$cnt]=$!
+                ((cnt++))
        fi
 }

Code:

#!/bin/bash
# /etc/rc.d/rc.local_shutdown
# Manage large, non-system, ext2/3/4 filesystem checks at
# shutdown rather than boot.  Tested with Slackware 13.1

# ver 0.3.final, em dot lazardo at gmail

function message () {
        logger -st rc.local_shutdown "$1"
}

function diskchk () {
        # 'tune2fs' and 'fsck' assume ext2/3/4 file system

        CUR_MCOUNT=(`tune2fs -l $DISK | grep '^Mount count:'`)
        message "$DISK mount count = ${CUR_MCOUNT[2]}/$MAX_MCOUNT"

        if [ ${CUR_MCOUNT[2]} -gt $MAX_MCOUNT ]; then
                umount -v $DISK
                if [ $? -ne 0 ]; then
                        message "cant unmount $DISK (fuser: `fuser -c $DISK`)"
                else
                        message "starting $DISK fsck"
                        ( fsck -yfC $DISK; message "finished $DISK fsck" ) &

                        PID[$cnt]=$!
                        ((cnt++))
                fi
        fi
}

# Exceptions ###############################################

# reboot
RUN_STAT=( `runlevel` )
case ${RUN_STAT[1]} in
        6|1|S|s)
                message "skipping fsck check (runlevel ${RUN_STAT[1]})"
                exit
                ;;
esac

# laptop on single battery
if [ -e /proc/acpi/battery ]; then
        BAT_STAT=`grep discharging /proc/acpi/battery/BAT0/state`
        if [ "$BAT_STAT" != "" ]; then
                message "skipping fsck check (battery)"
                exit
        fi
fi

# shutdown -f
if [ -e /fastboot ]; then
        message "skipping fsck check (shutdown -f)"
        exit
fi

# UPS
# One of these may work, neither was tested.
#
#if [[ -e /etc/apcupsd/powerfail || -e /etc/powerkill ]]; then
#        message "skipping fsck check (UPS)"
#        exit
#fi
#
#if [ -e /etc/powerstatus ]; then
#        UPS_STAT=`grep OK /etc/powerstatus`
#        if [ "$UPS_STAT" != "OK" ]; then
#                message "skipping fsck check (UPS)"
#                exit
#        fi
#fi

# main #####################################################
cnt=0

# Different MAX_MCOUNT values force serialization, identical values run in parallel.
# filesystems active at shutdown will not unmount and are not suitable.

message "Edit DISK and MAX_MCOUNT parameters to match your system and delete this line"

#DISK=/dev/md5; MAX_MCOUNT=13; diskchk                # serial
#DISK=/dev/md6; MAX_MCOUNT=14; diskchk                # serial
#DISK=/dev/sdc1; MAX_MCOUNT=15; diskchk                # parallel
#DISK=/dev/sdd1; MAX_MCOUNT=15; diskchk                # parallel

wait ${PID[*]}


Drakeo 09-24-2010 11:27 PM

I just stop running ext2 and ext3 Seems ext4 does my 500 gig drives with in seconds not minutes.
but thanks for the scripts

lazardo 10-02-2010 12:31 PM

Quote:

Originally Posted by Drakeo (Post 4108335)
I just stop running ext2 and ext3 Seems ext4 does my 500 gig drives with in seconds not minutes.
but thanks for the scripts

The script was created to help keep large, actively used media file collections on ext3 until ext4 has a bit more soak time (appologies to Ted Ts'o ;).

Cheers,

Richard Cranium 10-02-2010 09:51 PM

Why not use xfs instead?

lazardo 10-03-2010 01:09 AM

I've seen first hand the ugly underbelly of xfs corruption, performance and recovery issues at a 4 year storage startup stint, and that was with ex-SGI filesystem engineering on board. It's simply not suitable in non-commercial environments and/or without low-level engineering support.

I have a read-intensive, 'smaller numbers of larger files', low risk tolerance, low churn application and a lot of ext2/3 experience which tends to bias choices.

Cheers,


All times are GMT -5. The time now is 09:49 AM.