Files
DevOps/Linux/force fchk on every boot.md
2025-10-11 13:55:17 +02:00

3.7 KiB
Raw Permalink Blame History

Force fchk on every boot

LinuxConfig.org - How to force fsck to check filesystem after system reboot on Linux

View and modify PASS value in /etc/fstab

Now that we have learned about some tune2fs basics, lets discuss PASS system configuration option found inside of the /etc/fstab file containing all on boot mountable partitions and their relevant mount options.

First, use the blkid command to figure out the UUID value of the file system you want to check.

$ blkid /dev/sda3
/dev/sda3: UUID="c020d4d8-c104-4140-aafc-24f7f89f8629" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="22ada8f4-5222-4049-b0fe-a3274516754d"

Then, grep for that UUID in the /etc/fstab file.

$ grep c020d4d8-c104-4140-aafc-24f7f89f8629 /etc/fstab 
UUID=c020d4d8-c104-4140-aafc-24f7f89f8629 /               ext4    errors=remount-ro 0       0

The last column, which is column number 6, is the fsck PASS column. This is used by fsck to determine whether fsck should check the filesystem before it is mounted and in which order the given partitions in /etc/fstab should be checked. Possible entries for fstab PASS column are 0, 1 and 2. Here is what each number means.

0  disabled, that is do not check filesystem
1  partition with this PASS value has a higher priority and is checked first. This value is usually set to the root / partition
2  partitions with this PASS value will be checked last
The connection between fstab PASS value, last checked value, and number of mounts value is as follows:

During the system boot, the first value which is checked is fstab PASS value. If this value is 0, then no other values are checked and fsck will NOT perform filesystem check. However, if the PASS value found in /etc/fstab is 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 fscks 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

Force fsck for root or non-root partitions

To force filesystem check on a partition, we must first change fscks PASS value in /etc/fstab to value 2. For example: UUID=c6e22f63-e63c-40ed-bf9b-bb4a10f2db66 /mnt ext4 errors=remount-ro 0 2

After this change has been made, see the command examples below to finish forcing fsck to run.

To ensure that your file system is checked on the next reboot, we need to manipulate the filesystems “Maximum mount count” parameter. The following tune2fs command will ensure that filesystem /dev/sdX is checked every time your Linux system reboots. Please note that for this to happen the fscks PASS value in /etc/fstab must be set to a positive integer as discussed above.

$ sudo tune2fs -c 1 /dev/sdX

Note that this will continue to force fsck after every system reboot until you revert the setting.

Alternatively we can set fsck after every 10 reboots:

$ sudo tune2fs -c 10 /dev/sdX

Or to disable the setting, use the value -1.

$ sudo tune2fs -c -1 /dev/sdX

OR

$ sudo tune2fs -c 0 /dev/sdX