Monday, February 21, 2011

Tune File System Check (fsck) on ext Partitions in Ubuntu

The system utility fsck (for "file system check") is a tool for checking the consistency of a file system in Unix and Unix-like operating systems such as Linux.

Tuning /etc/fstab

The partitions on which you want to run a file system check are defined in /etc/fstab configuration file. By default, the root partitions and other system partitions like /home, /var, /log are set to be checked for file system errors after every 30 reboots.

# / was on /dev/sda1 during installation
UUID=c0ab9c52-02c2-4ef1-90d6-3bdc95d5ab8f     /          ext4    errors=remount-ro   0       1
# /home was on /dev/sdb1 during installation
UUID=2768e4c3-a250-4044-83e5-ffbf601a2ef7     /home      ext4    defaults            0       2

In the fstab example quoted above, the last digit in those lines is called a pass number. It controls the order in which fsck checks the partitions for errors at boot time. The root device should be 1, all other partitions should be 2, or 0 to disable checking. So with default settings, the '/' partition will be checked first and /home or any other partitions later for file system errors during boot. And this will happen at every 30th boot.

Manual fsck

fsck can't be run on mounted partitions and partitions being used like '/' or '/home' can't be unmounted. So fsck needs to be run at a reboot or from a Live CD/USB.

If you want to manually run fsck on any of your partitions on a reboot, simply this command will work.

sudo touch /forcefsck

It would force a fsck on all the partitions that are defined in your /etc/fstab and whose pass number is not '0'.

On unmounted partitions, you can run fsck by following this command.

sudo fsck -f /dev/sdXY

Where sdXY is your intended partition e.g, sda1, sda2, sdb1 etc.

If you want to run fsck in the non-interactive mode and let it remove all the errors automatically, put in the -y switch.

sudo fsck -f -y /dev/sdXY

Tune2fs

tune2fs allows the system administrator to adjust various tunable file system parameters on Linux ext2/ext3 file systems. Here you can adjust the no. of mounts after which your partitions are checked by fsck.

sudo tune2fs 10 /dev/sda1

This would make fsck check your sda1 partition after every 10 mounts.

More Info

See the man pages for more info.

man fsck
man tune2fs

Related Posts:

File System , System