LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices

Reply
 
Search this Thread
Old 09-15-2010, 02:22 AM   #1
lazardo
Member
 
Registered: Feb 2010
Location: SF Bay Area
Posts: 100

Rep: Reputation: Disabled
Post 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[*]}

Last edited by lazardo; 10-02-2010 at 11:33 AM. Reason: update unmount logic
 
Old 09-24-2010, 10:27 PM   #2
Drakeo
Senior Member
 
Registered: Jan 2008
Location: Urbana IL
Distribution: Slackware, Slacko,
Posts: 2,455
Blog Entries: 3

Rep: Reputation: 182Reputation: 182
I just stop running ext2 and ext3 Seems ext4 does my 500 gig drives with in seconds not minutes.
but thanks for the scripts
 
Old 10-02-2010, 11:31 AM   #3
lazardo
Member
 
Registered: Feb 2010
Location: SF Bay Area
Posts: 100

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Drakeo View Post
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,
 
Old 10-02-2010, 08:51 PM   #4
Richard Cranium
Senior Member
 
Registered: Apr 2009
Location: Carrollton, Texas
Distribution: Slackware64 14.1
Posts: 1,439

Rep: Reputation: 407Reputation: 407Reputation: 407Reputation: 407Reputation: 407
Why not use xfs instead?
 
Old 10-03-2010, 12:09 AM   #5
lazardo
Member
 
Registered: Feb 2010
Location: SF Bay Area
Posts: 100

Original Poster
Rep: Reputation: Disabled
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,
 
  


Reply

Tags
ext2, ext3, ext4, fsck, shutdown


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
fsck after improper shutdown jmkelm08 Linux - Software 1 07-05-2006 02:40 AM
How repair /usr partition using fsck, after finding errors during boot up? sarajevo Debian 1 12-08-2005 11:27 PM
automatic fsck on boot. fsck errors. nixel Slackware 1 05-17-2004 07:51 AM
Why such a large boot partition? nugui Linux - Newbie 3 11-13-2003 07:21 PM
System shutdown uncleanly; fsck? mac_phil Linux - General 2 11-02-2003 01:18 AM


All times are GMT -5. The time now is 12:32 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration