Sub topic 13
Reserved blocks and how ext4, XFS, and Btrfs differ
Prerequisites and the key distinction
This chapter assumes that you can use a Linux shell over SSH, read df output, use sudo, and distinguish a filesystem from a mounted directory.
A filesystem can report less space to ordinary users than its raw capacity. It may also keep metadata, allocation groups, or copy-on-write records that do not appear as ordinary files. These details vary by filesystem type, so a high df percentage does not always have the same meaning on ext4, XFS, and Btrfs.
Ext4 reserved blocks
Ext4 normally reserves a percentage of data blocks for the root user. The traditional default is 5%, although distributions and filesystem creation tools may choose different values. The reservation gives system services room to write logs and recover when regular users fill the filesystem. It also helps reduce fragmentation.
df usually reports the reserved space as unavailable to non-root users. The blocks are not missing, and deleting files as root can make them available again.
Inspect an ext2, ext3, or ext4 filesystem with:
sudo tune2fs -l /dev/sda1 | grep -i 'block count'This command shows several block-count fields, including the total and reserved counts. Replace /dev/sda1 with the actual device. Confirm the device first with findmnt or lsblk; changing the wrong filesystem is a serious error.
You can change the reserved percentage with tune2fs, but do so only after considering the server's role. A large general-purpose root filesystem may not need the historical 5% reservation. A small system partition, database volume, or busy logging volume may benefit from keeping more reserve. Reserved blocks do not solve inode exhaustion.
XFS allocation groups
XFS does not use ext4's simple, filesystem-wide reserved-block percentage. It divides the filesystem into allocation groups. Each group manages portions of free space and metadata, allowing large systems to allocate concurrently.
XFS can still reach an ENOSPC error, meaning an operation failed because the filesystem could not allocate the required resources. The apparent free-space percentage may not explain every failure. XFS may need space for metadata, directory growth, or allocation patterns. Quotas and project limits can also make a user or directory appear full while the filesystem has free space.
For XFS, inspect the filesystem type and mount options before changing anything:
findmnt -no SOURCE,FSTYPE,OPTIONS /var
df -hT /varDo not apply tune2fs to XFS. Use XFS-specific tools and documentation when you need allocation-group or metadata details.
Btrfs data, metadata, and snapshots
Btrfs uses copy-on-write. Instead of overwriting an existing block, it can write a new version and update metadata. Snapshots share unchanged data with their source, but changed data consumes additional space.
Btrfs allocates space in separate data and metadata chunks. A filesystem can therefore have apparently free raw space while lacking usable metadata space. Snapshots can also retain blocks after the original files are deleted. This is why ordinary directory searches may not explain all Btrfs usage.
The btrfs command reports filesystem-specific information:
sudo btrfs filesystem usage /
sudo btrfs filesystem df /Treat Btrfs “free” values as allocator information, not as a direct equivalent of ext4's free data blocks. Keep snapshot retention bounded and monitor metadata as well as data.
| Filesystem | Main space behavior | Common gotcha |
|---|---|---|
| ext4 | Data blocks plus a reserved root-only percentage | Reserved blocks are not inode reserves |
| XFS | Allocation groups and filesystem metadata | Quotas or metadata allocation can cause `ENOSPC` |
| Btrfs | Copy-on-write data and metadata chunks | Snapshots can retain deleted data |
Choosing an investigation path
Start with df -hT and df -ih. For ext4, inspect reserved blocks. For XFS, investigate allocation, quotas, and metadata with XFS tools. For Btrfs, inspect data and metadata chunks, snapshots, and scrub or balance policies. The same cleanup command can have different effects on each filesystem.
Exercise
Why is reducing ext4 reserved blocks not a fix for a filesystem with no free inodes?
Show answer
Reserved blocks are data-space blocks. Inodes are separate metadata entries, so inode exhaustion requires finding and removing unnecessary files or changing the filesystem design.