tune2fsfilesystem managing utility. Using
tune2fswe can export some important information related to filesystem health check. The following command will tell as when was the last time the filesystem
# tune2fs -l /dev/sdbX | grep Last\ c Last checked: Sun Dec 13 09:14:22 2015Anther useful information which can be retrieved by
tune2fscommand relates to how many times our
/dev/sdXfilesystem was mounted:
# tune2fs -l /dev/sdbX | grep Mount Mount count: 157and lastly how many mounts are allowed to pass before filesystem check is forced:
# tune2fs -l /dev/sdbX | grep Max Maximum mount count: -1From the above outputs we can establish the following information summary. The
/dev/sdbXfilesystem was last checked on
Sun Dec 13 09:14:22 2015. Since the last check, this filesystem was mounted
157times and maximum amount of mounts before next filesystem fsck check. In the above case the value
-1means that fsck is disabled.
tune2fsbasics let's discuss PASS system configuration option found in
/etc/fstabfile containing all on boot mountable partitions and their relevant mount options.
# blkid | grep sdb1 /dev/sdb1: UUID="c6e22f63-e63c-40ed-bf9b-bb4a10f2db66" TYPE="ext2" # grep c6e22f63-e63c-40ed-bf9b-bb4a10f2db66 /etc/fstab UUID=c6e22f63-e63c-40ed-bf9b-bb4a10f2db66 /mnt ext2 errors=remount-ro 0 0We have used
blkidcommand to retrieve UUID for a given partition and then used the retrieved partition UUID to get a relevant information related to
/etc/fstbab. The last column that is a column 6, aka fsck PASS column is used by fsck to determine whether fsck should check filesystem before it is mounted and in which order given partitions in
/etc/fstabshould be checked. Possible entries for fstab PASS column are 0,1 and 2.
fsckwill NOT perform filesystem check. If the PASS value found in
/etc/fstabis any other than 0, that is 1 or 2 then values of maximum mounts and total mounts are checked. If the value of maximum mounts is greater or equal to total number of mounts value then fsck's filesytem check will be performed. Few examples:
FSCK DISABLED fstab PASS: 1 Maximum mount count: -1 Mount count: 157 ---- FSCK DISABLED fstab PASS: 0 Maximum mount count: -1 Mount count: 157 ---- FSCK ON NEXT REBOOT fstab PASS: 1 or 2 Maximum mount count: 1 Mount count: 157 ---- FSCK DISABLED fstab PASS: 0 Maximum mount count: 1 Mount count: 1 ---- FSCK ON NEXT REBOOT fstab PASS: 1 or 2 Maximum mount count: 1 Mount count: 1 ---- NO FSCK ON NEXT REBOOT fstab PASS: 1 or 2 Maximum mount count: 200 Mount count: 157
/dev/sda1is to create an empty file called
forcefsckin the partition's root directory.
# touch /forcefsckThis empty file will temporarily override any other settings and force
fsckto check the filesystem on the next system reboot. Once the filesystem is checked the
forcefsckfile will be removed thus next time you reboot your filesystem will NOT be checked again. To enable more permanent solution and force filesystem check on every reboot we need to manipulate filesystem's "Maximum mount count" parameter. The following command will ensure that filesystem
/dev/sdb1is checked every time your Linux system reboots. Please note that for this to happen the fsck's PASS value in
/etc/fstabmust be set to a positive integer as discussed above.
# tune2fs -c 1 /dev/sdb1alternatively we can set fsck after every 10 reboots:
# tune2fs -c 10 /dev/sdb1
forcefsckfile will NOT trigger partition check on reboot. The only way to force fsck on all other non-root partitions is to manipulate filesystem's "Maximum mount count" parameter and PASS value within
/etc/fstabconfiguration file. To force filesystem check on non-root partition change fsck's PASS value in
/etc/fstabto value 2. For example:
UUID=c6e22f63-e63c-40ed-bf9b-bb4a10f2db66 /mnt ext2 errors=remount-ro 0 2and change maximum mounts filesystem parameter to a positive integer, depending on how many times you wish to allow a specified filesystem to be mounted without being checked. Force fsck on every reboot:
# tune2fs -c 1 /dev/sdb1alternatively we can set fsck to check filesystem after every 5 reboots:
# tune2fs -c 5 /dev/sdb1To disable fsck run:
# tune2fs -c 0 /dev/sdb1 OR # tune2fs -c -1 /dev/sdb1Which will set the filesystem's "Maximum mount count" parameter to