Friday, August 18, 2006

fsck automatically on reboot

Here's a nice little trick I found.

I had a couple of hard reboots, due to power failures and I wanted to have all the ext3 filesystems in my fstab to be checked during the next reboot. Here's what I did.

There's an option in tune2fs, -C, which allows one to manually set the mount count for an ext2/3 filesystem. By default, on my Gentoo installation, all the ext3 filesystems are checked automatically after 38 mounts or 180 days, whichever happens earlier. By using tune2fs, one can set the mount count of a filesystem to be greater than this value and the filesystem will be automatically checked when the system boots up next time..

I did a
tune2fs -C 50

for all the ext2/3 filesystems in my fstab and they were all checked upon the next reboot.

Another way of doing this would be to change number of days since the filesystem was last checked to be greater than that value of 180. This can be done with the -T option of tune2fs.

In case you're wondering, you can change the default values of the mount count or the day limit using the -c and -t options to tune2fs respectively. As always, check man tune2fs for details ;)


Arnaud said...

It's probably easier to perform a "touch /forcefsck" before rebooting, which will force the fsck on all filesystem...

floyd_n_milan said...

Aah, I didn't know that one! Thanks :D