Search This Blog


Saturday, November 29, 2008

How to increase number of disk mounts before next fsck at system boot

Many home users often power off their computers when they are not being used. Some do it to be green: turning idle computers off saves electricity and $$. Others do it for the extra security. To those who are hard-core Linux geeks, machine uptime is sacred, and voluntarily rebooting the machine is nothing but sacrilegious.

If you do reboot your machine from time to time, you most definitely have encountered a most annoying experience. Once in a while, while the computer is booting up, you see the message /dev/hdaN has reached maximal mount count, check forced. The check seems to take forever, and the system boot won't resume until the check is over.

The check refers to a file system check performed using the fsck command. For many Linux distributions, by default, the system will do a fsck check on a file system after it has been mounted 30 times, which means after 30 reboots. This is the maximum mount count before fsck is performed on the file system.

You can specify a maximum mount count for each individual partition on your hard drive. To find out the maximum mount count for /dev/hda1, execute this command as root:
$ tune2fs -l /dev/hda1 | grep 'Maximum mount count'
Maximum mount count: 30

Note that the tune2fs command is only applicable for ext2 and ext3 file systems.

The tune2fs command can also tell you how many times a file system has actually been mounted since the last fsck check.
$ tune2fs -l /dev/hda1 |grep 'Mount count'
Mount count: 17

To increase the maximum mount count, you will use the same tune2fs command but with the -c option.

Note that you should not modify the maximum mount count which is a file system parameter while the file system is mounted. The recommended way is to boot your system using a Linux Live CD, and then run tune2fs.

For me, I happened to have a Ubuntu 7.10 Live CD at my desk. I inserted the Live CD to boot up my system. Then, I opened a Terminal window, sudo -s, and executed the following commands.

First, I reminded myelf of how the /dev/hda disk is partitioned:
$ fdisk -l /dev/hda
Disk /dev/hda: 82.3 GB, 82348277760 bytes
255 heads, 63 sectors/track, 10011 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/hda1 * 1 31 248976 83 Linux
/dev/hda2 32 10011 80164350 5 Extended
/dev/hda5 32 10011 80164318+ 8e Linux LVM

To increase the maximum mount count to 50 for /dev/hda1:
$ tune2fs -c 50 /dev/hda1
tune2fs 1.40.2 (12-Jul-2007)
Setting maximal mount count to 50

If there are more than 1 file system on your hard drive, you should stagger the maximum mount count for the different file systems so that they don't all trigger the lengthy fsck at the same time. For example, set the maximum mount count to 40, 50 and 60 for /dev/hda1, hda2, and hda3 respectively.

In the above case, /dev/hda5 is a physical LVM volume. You cannot run tune2fs on physical LVM volumes directly.
$ tune2fs -l /dev/hda5
tune2fs 1.40.2 (12-Jul-2007)
tune2fs: Bad magic number in super-block while trying to open /dev/hda5
Couldn't find valid filesystem superblock.

You need to run tune2fs against each logical LVM volume. To find out their names, cat /etc/fstab.
$ tune2fs -c 60 /dev/mapper/myhost-root 
tune2fs 1.40.2 (12-Jul-2007)
Setting maximal mount count to 60

StumbleUpon Toolbar


zugwang said...

Excellent! Just what I was looking for.

I have myself a blog (in spanish, If you don't mind I will translate you article. Of course I will give you all the credits.

Peter Leung said...


Glad you found it useful. By all means, please translate it.


Anonymous said...

THis what i was looking for. Thanks buddy

NIZHAL said...

how long will it take to run tune2fs on a 10TB lvm?

shirishag75 said...

I don't think it will take much time. I *think* it just reads some information at the beginning and you are manipulating that.