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%.

3 Responses to “Freeing Disk Space in Linux”

  1. trent Says:

    As I recall, another reason that buffer of free space is left there is because as the filesystem gets more full the performance goes non-linear (due to fragmentation causing excessive disk seeks, etc). Of course, this decision was made back when we had giant cabinets with a couple hundred megs, so that reserved space seems kind of silly with terrabyte disks. Also, I don’t know how much of a problem this is for modern filesystems (like ext).

    There’s some more info here: http://unix.stackexchange.com/questions/7950/reserved-space-for-root-on-a-filesystem-why

    [Reply]

  2. Gabriel Blankenship Says:

    I’ll just paste the string I’m working on encase anyone could use any part of it, just a basic script to filter out just the % of free space a file system has on it without the % symbol which is set as a variable.

    [code]avail=`df -h |grep usr |awk '{print $4}' |awk '{gsub(/%/, ""); print}'`[/code]

    [Reply]

  3. Reclamando espacio reservado en particiones Ext en Linux Says:

    [...] temporal o algo similar que permitiera esto? Pues bien buscando un poco encontré la razón (http://backdrift.org/freeing-disk-space-in-linux). Al parecer en las particiones de disco ext (ext1, ext2, ext3, ext4) se reserva un porcentaje de [...]

Join the Conversation