Reclaim free space on your server ‘with this weird trick’ (KVM/Xen/dedi only)

This quick tutorial will help you reclaim free space on your servers or Xen/KVM VPSes. This post can be considered as a re-post the method from LowEndTalk discussion topic. The source can be found HERE.

By default the Ext2/3/4 filesystems are created with a setting to set aside 5% of free space for the root user, not shown in the free space count and not usable by other users and their programs. This is done “just in case”, with practically just one scenario in mind: if something goes wrong and your server consumes all its free disk space, the root user could still log in and check logs/crash dumps/etc and generally fix the situation.

Let say if you have a 10G HDD, 5% is just 512MB, on 500G it is around 25GB. However, in my backup system which has 2TB disk, 5% mean 100G which I cannot use and it is really the waste. Let’s check this:

[bash]# df -h
Filesystem Size Used Avail Use% Mounted on
rootfs 20G 1018M 18G 6% /
/dev/root 20G 1018M 18G 6% /
devtmpfs 2.0G 216K 2.0G 1% /dev
/dev/sda3 1.8T 1.7T 74G 96% /home
tmpfs 2.0G 0 2.0G 0% /dev/shm
/dev/root 20G 1018M 18G 6% /var/named/chroot/etc/named
/dev/root 20G 1018M 18G 6% /var/named/chroot/var/named
/dev/root 20G 1018M 18G 6% /var/named/chroot/etc/named.conf
/dev/root 20G 1018M 18G 6% /var/named/chroot/etc/named.rfc1912.zones
/dev/root 20G 1018M 18G 6% /var/named/chroot/etc/rndc.key
/dev/root 20G 1018M 18G 6% /var/named/chroot/usr/lib64/bind
/dev/root 20G 1018M 18G 6% /var/named/chroot/etc/named.iscdlv.key
/dev/root 20G 1018M 18G 6% /var/named/chroot/etc/named.root.key[/bash]

Then, I want to reduce the “reserving space” for root user to 1%, meaning 20G (more than enough):

[bash]# tune2fs -m 1 /dev/sda3
tune2fs 1.41.12 (17-May-2010)
Setting reserved blocks percentage to 1% (4831265 blocks)[/bash]

Then check the final result:

[bash]# df -h
Filesystem Size Used Avail Use% Mounted on
rootfs 20G 1018M 18G 6% /
/dev/root 20G 1018M 18G 6% /
devtmpfs 2.0G 216K 2.0G 1% /dev
/dev/sda3 1.8T 1.7T 148G 92% /home
tmpfs 2.0G 0 2.0G 0% /dev/shm
/dev/root 20G 1018M 18G 6% /var/named/chroot/etc/named
/dev/root 20G 1018M 18G 6% /var/named/chroot/var/named
/dev/root 20G 1018M 18G 6% /var/named/chroot/etc/named.conf
/dev/root 20G 1018M 18G 6% /var/named/chroot/etc/named.rfc1912.zones
/dev/root 20G 1018M 18G 6% /var/named/chroot/etc/rndc.key
/dev/root 20G 1018M 18G 6% /var/named/chroot/usr/lib64/bind
/dev/root 20G 1018M 18G 6% /var/named/chroot/etc/named.iscdlv.key
/dev/root 20G 1018M 18G 6% /var/named/chroot/etc/named.root.key[/bash]

 

As you can see, in some backup system with very large disk and space is one of the critical one in your concern, it should be better to save as much as unused space as we can 🙂

Leave a comment

Your email address will not be published. Required fields are marked *