Lot of system administrators and devops use large drives to host or backup data. However, what they don’t know is that they are losing a few % of disk space on each drive. Today we will explore a tutorial to free disk space by reducing reserved blocks.
This will lead to have more free disk space to be used in your web applications or backups.
Reserved Blocks on Linux
Large drives like 1TB, 2TB or even more, are usual on new dedicated server configurations. The datacenter makes the setup, install the OS on your drives, format with ext3 or ext4 filesystems, and your new fresh dedicated machine is ready to be used.
When you explore the drives using df -ah, you will notice the 1TB drives don’t have that much space available, but about 900GB. You are losing 10% of your disk capacity, that’s normal in fact. However, what you don’t know is that you can free disk space by reducing reserved blocks.
Reserved blocks on Linux it’s just as the word is saying, a small part of the disk is reserved for privileged process. This is done in case the filesystem fills up, the important tasks and system processes will still be able to work and write to the drive.
By default on most modern Linux distros like Fedora, CentOS, Ubuntu/Debian, the reserved blocks on Linux is around 5%. On this days, where almost all dedicated servers come with 1TB drives, this means around 50GB or 100GB if you have 2TB drive, that’s too much space.
If you have a very large filesystem like the one we mentioned, you can reduce the reserved percentage of blocks to free up disk space on your box.
How can I Free Disk Space Reducing Reserved Blocks?
If you’ve got a large filesystem, or a filesystem which does not store your Linux system files, it’s safe to reduce the percentage of reserved blocks to free up that disk space.
tune2fs is a command tool that allows you to change this reserved disk space on Linux operating systems.
Let’s see some examples:
Reduce reserved blocks on /dev/sdb1 from 5% to 1%
tune2fs -m 1 /dev/sdb1
Make sure you replace /dev/sdb1 with the partition path you need to reduce. You can get the full list of partitions and mount points using df command, for example:
Step by step guide to free disk space reducing reserved blocks
Locate the partition you need to resize
[email@example.com:~]df -ah Filesystem Size Used Avail Use% Mounted on /dev/sda3 108G 16G 88G 15% / proc 0 0 0 - /proc sysfs 0 0 0 - /sys devpts 0 0 0 - /dev/pts none 3.9G 0 3.9G 0% /dev/shm /dev/sda1 473M 133M 316M 30% /boot /dev/sdb1 917G 8.4G 862G 1% /home /dev/sdc1 917G 697M 870G 1% /backup none 0 0 0 - /proc/sys/fs/binfmt_misc /usr/tmpDSK 4.0G 137M 3.7G 4% /tmp /tmp 4.0G 137M 3.7G 4% /var/tmp
As you see, this system has 3 drives: 120 GB SSD on /dev/sda3, 1TB on /home and 1TB mounted on /backup directory.
Let’s try to free disk space reducing reserved blocks for /home partition.
[firstname.lastname@example.org:~]df -ah | grep home /dev/sdb1 917G 8.4G 862G 1% /home
There are 862GB of free disk space right now, with 5% of reserved blocks. Let’s reduce that to 1%.
[email@example.com:~]tune2fs -m 1 /dev/sdb1 tune2fs 1.41.12 (17-May-2010) Setting reserved blocks percentage to 1% (2441900 blocks)
Let’s check again to see how much free disk space we have now
[firstname.lastname@example.org:~]df -ah | grep home /dev/sdb1 917G 8.4G 900G 1% /home
900 GB, that’s 38GB of extra free disk space.
Reserved blocks on Linux run a very important task, preserve the disk space in case your disk is totally filled up to enable important system functions to still run without any issues.
However, on large drives there is no need to have 5%, you can reduce this to 1% or 2% and your system will still be safe at all times.
At this point you know how to free disk space reducing reserved blocks on Linux systems running ext2/ext3/ext4 filesystems.