Tuesday, August 2, 2011

when fsck runs at boot

Sometimes when you boot into Linux,  fsck runs and checks this or that filesystem (partition). This is a good thing, even though sometimes you wish it wouldn't because you're in a hurry!  You can see which filesystems will be checked at boot time by looking at the file /etc/fstab.

Partition info is shown in /etc/fstab under these columns: file system, mount point, type, options, dump, pass. According to man fstab, the numbers under the last column (pass) determine the order in which filesystem checks are done at boot time.

The entry for the root filesystem should have a "1" under the "pass" column. Other filesystems will have a "2" under this column; man fstab says, "Filesystems within a drive will be checked  sequentially,  but  filesystems  on  different drives  will  be checked at the same time to utilize parallelism available in the hardware."

If there's a "0" under the "pass" column, or if there's nothing present there, then fsck assumes that the filesystem does not need to be checked.

fsck will run at boot time after the filesystem has been mounted a set number of times, or if that number hasn't been reached, after a set time interval. For ext2, ext3, and ext4 partitions, you can find a bunch of info about a filesystem, including last mount time, mount count, maximum mount count (before fsck runs), last time checked, check interval, and next scheduled check (according to the check interval) by using the tune2fs and/or dumpe2fs commands.

The following two commands output mostly the same info (see man tune2fs and man dumpe2fs) -- I can use either of them for getting info about the partition at sda7 in Debian Squeeze (run as root):

#  tune2fs -l /dev/sda7

#  dumpe2fs -h /dev/sda7

Piping either of these commands into grep, with the -i flag (to ignore case), gives me the output relating only to the info I'm looking for in this situation:

#  tune2fs -l /dev/sda7 | grep -i 'mount count'
Mount count:              5
Maximum mount count:      24

#  tune2fs -l /dev/sda7 | grep -i 'check'
Last checked:             Fri Jul 29 21:52:37 2011
Check interval:           15552000 (6 months)
Next check after:         Wed Jan 25 20:52:37 2012

Or I can use egrep to get the above info all from one command:

#  tune2fs -l /dev/sda7 | egrep -i 'mount count|check'
Mount count:              5
Maximum mount count:      24
Last checked:             Fri Jul 29 21:52:37 2011
Check interval:           15552000 (6 months)
Next check after:         Wed Jan 25 20:52:37 2012

Or:

#  dumpe2fs -h /dev/sda7 | egrep -i 'mount count|check'
dumpe2fs 1.41.12 (17-May-2010)
Mount count:              5
Maximum mount count:      24
Last checked:             Fri Jul 29 21:52:37 2011
Check interval:           15552000 (6 months)
Next check after:         Wed Jan 25 20:52:37 2012

No comments: