Freeing Disk Space in Linux

Tags: , , , , , , , , , , , , , , , , , , ,

Did you know that most filesystems reserve a percentage of the available free space as an emergency reserve for when the disk becomes full? This is a great safety mechanism if you’re running critical applications or database, but in many cases all this reserved space winds up going to waste. Especially so in the case of today’s 2 & 3 Terabyte disks!

On a linux EXT filesystem, 5% is reserved for access only by the root user. Assuming you have a 2T disk this is approximately 100G reservation, which is total overkill if you ask me! Luckily it’s easy enough to adjust on-the-fly with the tune2fs command.

For this example I’m going to change the number of reserved blocks from the default of 5% to 1% on the filesystem mounted as /misc.

A simple df -h will show you free space minus the reserve.

[root@foo ~]# df -h | grep misc
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda5             789G  110G  639G  15% /misc

As you can see, there is 639G of free space on this filesystem.

Now, we use tune2fs -m 1 to change the percentage reserved to 1%

[root@foo ~]# tune2fs -m 1 /dev/sda5
tune2fs 1.39 (29-May-2006)
Setting reserved blocks percentage to 1% (2133291 blocks)

Now we check the available space

[root@foo ~]# df -h | grep misc
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda5             789G  110G  672G  14% /misc

Now we have 672G free. That’s 33G of storage we just got back for free!

Now, it may seem attractive to set this to 0% to squeeze the most possible free space from your drive, and under some circumstances this is perfectly safe to do. However, don’t set this to 0% if you have processes running as root that you want to continue running if the disk fills. Here’s a simple of thumb if you’re not sure. If you’ll loose irreplaceable data (or your job) if this filesystem goes casters up, don’t set to 0%.