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
2
3
$ df /mnt/sdb/
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sdb 1922860936 1839798972 0 100% /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
2
$ mkdir hello
mkdir: cannot create directory `hello': No space left on device

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
2
3
$ sudo tune2fs -l /dev/sdb | grep -i 'block count'
Block count: 488378646
Reserved block count: 24418932

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
2
3
$ df -l /mnt/sdb/
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sdb 1922860936 1839798968 83061968 96% /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
2
3
$ df -i /mnt/sdb/
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/sdb 122101760 41070990 81030770 34% /mnt/sdb

Comments

2014-07-06