Sunday, October 31, 2010

Increase available disk space by decreasing the reserved blocks in extended filesytems ext2/3/4 using tune2fs

Have you ever noticed that after formatting a partition or external storage device - hard disk etc. into ext2/3/4 decreases the total available disk space by some amount? That's because the file-system reserves some part of the space to privileged processes. This is done to make sure that in case of file-system fill up, when user processes may not be allowed to write to disk, privilege system processes(or root user) may still be able to function properly(write on disk) e.g. syslogd etc.

This space by default is around 5% of the total. And considering the amount of hard-drive or partitions available these days, this reserved memory could be huge e.g. 5% of 500GB hard disk is 25GB, which is too much for critical cases. And this memory is only needed in the root(/) partition and it doesn't make much sense to reserve blocks on /home partitions or external storage devices, because privileged processes don't usually write on home partition.

It should be noted that this reserved space is also used to reduce fragmentation. So, it plays a major role in avoiding fragmentation by preventing the disk to be filled completely.

So, if you think 5% of your partition/disk is more than enough for reserved blocks then you can save some space by decreasing this amount. You can do this by using the tune2fs utility.

[root]# tune2fs -m 3 /dev/sda1

The -m option is used to set the new percentage share, we used 3%. /dev/sda1 is my root(/) partition.

We can set the value to 0 for home partition, assuming that you haven't configured any privileged process to write in /home directory. A word of warning here, since these reserved blocks are also used to prevent fragmentation, leaving some amount is a good idea.

[root]# tune2fs -m 0 /dev/sda2

where /dev/sda2 is the home partition.

You can even check the current number of reserved blocks on a partition or disk using tune2fs.

[root]# tune2fs -l /dev/sda2 | grep -i reserve

Reserved block count: 1257387
Reserved GDT blocks: 1018
Reserved blocks uid: 0 (user root)
Reserved blocks gid: 0 (group root)