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[*]}