Releasing the 5% Disk Space Eaten by the File System
Those who use the ext file system to store data may have noticed that a 200 G partition can only use 190 G, and a 2000 GB partition can only use 1900 GB. Where did this 5% disk space go? Some people think this is the difference between the decimal system (1000) and the binary system (1024), but this is not the case.
1 | $ df /mnt/sdb/ |
The available space of the above-mentioned 2 T disk is 0, which seems to be full. Try to create a directory and find that there is no space left.
1 | $ mkdir hello |
But sudo mkdir hello can succeed! What’s going on? The answer lies in the “reserved space” of the ext file system.
A long, long time ago, there was no concept of disk partitioning, only one file system, and system data and user data were all placed on it. This brings up a problem, if some users fill up the disk, then system logs cannot be written, and even remote login may not work. To prevent low-privilege users from filling up the disk and interfering with system operation, the ext file system reserves 5% of disk space for the root user, that is, when disk usage reaches over 95%, ordinary users cannot write new data, only root can write new data, this ensures that system services running as root can write logs normally.
Times have changed, and now on PCs and servers, system data and user data are mostly stored in different partitions, and user data partitions often have hundreds of G or even T. Reserving 5% of disk space for root in the user data partition is not only unnecessary, but also a great waste. Unfortunately, the installation programs of all the GNU/Linux distributions I have seen have not considered this point and still format partitions with default parameters.
How to see these reserved disk spaces? Suppose the partition of the ext file system is /dev/sdb:
1 | $ sudo tune2fs -l /dev/sdb | grep -i 'block count' |
A block is generally 4 KB, you can see that the Block count matches the 1K-blocks number displayed by df. And the Reserved block count just takes up 5%.
To release these disk spaces eaten by the file system (that is, to allow users other than root to use it), one command, effective immediately:
1 | sudo tune2fs -m 0 /dev/sdb |
Then the disk instantly “gains” tens of G of space… When your data partition is almost full, you might as well try tune2fs -m 0, and taste the feeling of the disk utilization rate dropping by 5% instantly.
1 | $ df -l /mnt/sdb/ |
Also note that the number of inodes in the ext file system is also limited, each directory and file takes up one inode, sometimes the disk space is not full, but the inodes are full, and new files cannot be created. You can use df -i or tune2fs -l to check the usage of inodes:
1 | $ df -i /mnt/sdb/ |