Part 5 of 7 · 2 min read
Reserved and inodes
Think of a bus with a few seats kept for staff. When the visible seats are taken, the bus is full for the public, though a count of the seats shows some free. The analogy stops in one place: a bus keeps its staff seats in sight, while the reserved blocks of a disk are hidden in the free count.
In plain words: ext4 reserves a share of the blocks, 5% by default, for the superuser. The reason is that a full disk would block the tools that are needed to repair it, and that a disk that is nearly full fragments badly. An ordinary user gets "no space left on device" when the free blocks fall to the reserve, while df may still show a few per cent of free space. The count is in the superblock. Separately, the number of inodes is fixed (page 2). When they are used up, creating files fails, although many blocks are free.
A worked example. tune2fs -l on the image printed:
Inode count: 8192
Block count: 8192
Reserved block count: 409
Free blocks: 6643
Free inodes: 8181
Of 8,192 blocks, 409 are reserved, which is 5% (8,192 x 0.05 = 409.6, rounded down). That is 409 x 4 KiB = 1,636 KiB that an ordinary user cannot use. df showed 24,284 KiB available, which is 2,288 KiB less than its Size minus Used (26,596 - 24 = 26,572). The reserved blocks are part of that gap. I did not trace the rest of the difference. The inode figures show 8,181 of 8,192 free, so the image was far from running out of inodes. Page 2 showed the case with 128 inodes, which stopped after 117 files while the blocks were 1% used.
The key lines. The reserve can be changed with tune2fs -m (the percentage), for example to 1% on a large data disk. It is a policy, not a law of the file system. On a 4 TiB data disk, 5% is 200 GiB, which is a large amount to leave unused.
Reserved blocks
Reserved blocks are a part of the blocks of an ext file system that only privileged users can allocate. They remain free for the system's own use when the disk is nearly full. They are counted as free by the file system and are not available to ordinary users, so df shows them as missing from the "Avail" column.
Example: 409 of the 8,192 blocks of the test image are reserved, which is 5%.
Interview angle
A common question is "df says the disk is full but du shows much less. Why?" A good answer lists the causes in order: a deleted file that a process holds open, a different mount hidden under a mount point, sparse files, reserved blocks and metadata, and then inodes, with the command that checks each.
Check yourself: 1. What share of blocks does ext4 reserve by default? 2. Why does the reserve exist? 3. Which command shows inode use?