How to force fsck to check filesystem after system reboot on Linux 2/2

Categories:  linux,
Labels:  OS

1. Force fsck for root partition

The simplest way to force fsck filesystem check on a root partition eg. /dev/sda1 is to create an empty file called forcefsck in the partition’s root directory.

# touch /forcefsck

This empty file will temporarily override any other settings and force fsck to check the filesystem on the next system reboot.
Once the filesystem is checked the forcefsck file 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/sdb1 is checked every time your Linux system reboots. Please note that for this to happen the fsck’s PASS value in /etc/fstab must be set to a positive integer as discussed above.

# tune2fs -c 1 /dev/sdb1

Alternatively we can set fsck after every 10 reboots:

# tune2fs -c 10 /dev/sdb1

2. Force fsck for all other non-root partitions

As oppose to root partition creating empty forcefsck file 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/fstab configuration file. To force filesystem check on non-root partition change fsck’s PASS value in /etc/fstab to value 2. For example:

UUID=c6e22f63-e63c-40ed-bf9b-bb4a10f2db66 /mnt            ext2    errors=remount-ro 0      2

And 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/sdb1

Alternatively we can set fsck to check filesystem after every 5 reboots:

# tune2fs -c 5 /dev/sdb1

To disable fsck run:

# tune2fs -c 0 /dev/sdb1

OR

# tune2fs -c -1 /dev/sdb1

Which will set the filesystem’s “Maximum mount count” parameter to -1

Social Profiles

This web accept cryptocoin donations
BTC address, LTC, ETH, DASH, Uphold:
Why donations?