How to force filesystem check on a particular drive during system reboot in Linux ?
In this article, we will look at one of the interesting topic “how to force a filesystem to perform filesystem check during system boot next time”.
The old trick was to create a /.autofsck file on the partition root and it will perform the fsck.
1. Old trick to force fsck on reboot.
### Create a file /.autofsck. [root@nglinux ~]# touch /.autofsck [root@nglinux ~]# ls -al /.autofsck -rw-r--r--. 1 root root 0 Jan 14 03:26 /.autofsck ### Now reboot the system to check that fsck would be performed. [root@nglinux ~]# init 6
2. Using debugfs, the perfect and sure way to perform the task.
Here we will see how to force filesystem check by changing the filesystem state using debugfs command.
a. First Open the filesystem on which you want to perform fsck in read-write mode.
debugfs: open -w /dev/sda5 debugfs: params Open mode: read-write
b. Make the filesystem dirty by executing the “dirty” command twice.
debugfs: dirty debugfs: dirty
c. Now check the stats to verify if filesystem state is changed to “not clean”
debugfs: stats ### From : Filesystem state: clean ### To: Filesystem state: not clean
Yes the state is finally changed.
Now lets reboot the system now and look for fsck working on this filesystem.
Another trick is to make changes using tune2fs or /etc/fstab file, however in all these cases, you need to revert the chnages after reboot.
I hope you liked the above trick.
Please feel free to post your comments/suggestions below.