Sub topic 13
Reserved Blocks and How ext4, XFS, and Btrfs Differ
This chapter assumes you can read df and df -i output and know that a filesystem has a block limit and an inode limit. You should also be comfortable running commands with sudo. Here you will see why df sometimes shows less free space than you expect, and why the same alert threshold means different things on different filesystem types.
What reserved blocks are
On ext2, ext3, and ext4, the filesystem holds back a share of its blocks for the root user. The default is 5% of the total. Ordinary users cannot allocate those blocks. Root and processes running with the right capability can.
There are two reasons for the reserve:
- A full disk can still be repaired. If a runaway process fills the disk as a normal user, root can still write logs, create temporary files, and run cleanup tools.
- Free space helps the allocator. When a filesystem is almost full, ext4 has trouble finding contiguous free blocks, and files fragment. A reserve keeps some room for it to work.
On a small root filesystem this is sensible. On a 4 TB data volume, 5% is about 200 GB that no application can use, and the reserve does nothing useful there.
How the reserve shows up in df
df reports three numbers that do not add up on ext4:
- Size is the total capacity.
- Used is the blocks in use.
- Avail is what a non-root user can still allocate.
The reserve is the gap between them. Percent is calculated as Used divided by (Used + Avail), so Use% reaches 100% when the filesystem is only about 95% full in raw terms.
df -hT /dataA typical result on a freshly formatted ext4 volume:
Filesystem Type Size Used Avail Use% Mounted on
/dev/sdb1 ext4 9.8G 24K 9.3G 1% /dataThe volume is empty, yet Used plus Avail is 9.3 GB, not 9.8 GB. The missing space is the reserve (about 5%) plus a small amount of filesystem metadata.
Reading the exact numbers
Use tune2fs to see the reserve directly. Replace the device name with your own.
sudo tune2fs -l /dev/sda1 | grep -i 'block count'This prints two lines, Block count and Reserved block count. To turn them into a percentage:
sudo tune2fs -l /dev/sdb1 | awk -F: '/^Block count/ {b=$2} /^Reserved block count/ {r=$2} END {printf "%.1f%% reserved\n", 100*r/b}'On a default ext4 filesystem this prints 5.0% reserved.
Changing the reserve
You can change the reserve on a mounted ext4 filesystem. -m sets a percentage, and -r sets an exact block count.
sudo tune2fs -m 1 /dev/sdb1Choose the value by the role of the filesystem:
| Filesystem role | Suggested reserve | Reason |
|---|---|---|
| Root (`/`) or `/var` with logs | Keep 5%, or at least 2% | Root and system services need room to write when users fill the disk |
| Data volume used only by one application | 0% to 1% | No root-owned processes depend on the space |
| Very large volume (multiple TB) | 1% or less | 5% is a large absolute amount |
Do not set the reserve to zero on / or /var. A full root filesystem can stop logins, package updates, and the logging daemon.
Different filesystems, different rules
Before you act on df output, find out which filesystem type you are looking at.
findmnt -no FSTYPE,SOURCE /dataThe three common types handle space and inodes differently.
| Feature | ext4 | XFS | Btrfs |
|---|---|---|---|
| Reserved space for root | Yes, 5% by default, adjustable with `tune2fs` | No percentage reserve, only a small internal pool | No percentage reserve, but a global metadata reserve |
| Inode count | Fixed when the filesystem is created | Allocated on demand, limited by `imaxpct` | Allocated on demand, no fixed limit |
| `df -i` is meaningful | Yes | Yes, but watch the `imaxpct` ceiling | No, usually shows `0` or `-` |
| Can shrink | Yes, offline | No | Yes, online |
| Best tool for real usage | `df`, `tune2fs -l` | `df`, `xfs_info` | `btrfs filesystem usage` |
ext4: fixed inodes
ext4 decides how many inodes to create when you run mkfs.ext4. By default it creates one inode per 16 KiB of space. Later you cannot add inodes without reformatting. A volume that will hold millions of tiny files should be created with a lower bytes-per-inode ratio (mkfs.ext4 -i 4096 /dev/sdX) or an explicit inode count (-N).
This is why inode exhaustion is a real ext4 failure. The disk can be 20% full by blocks and still refuse to create a file.
XFS: dynamic inodes with a ceiling
XFS creates inodes as needed, so you rarely run out by count. It does limit the share of the filesystem that inodes may occupy. That limit is imaxpct, and xfs_info shows it.
xfs_info /dataLook for imaxpct=25 on the data line. The default is 25% for filesystems under 1 TB, 5% from 1 TB to 50 TB, and 1% above 50 TB. If df -i shows IUse% climbing on XFS, you are approaching this ceiling, not a fixed count. You can raise it on a mounted filesystem:
sudo xfs_growfs -m 30 /dataXFS also keeps a small internal reserve of blocks so that operations such as deleting files can still complete when the filesystem is full. You can inspect it, though you rarely need to.
sudo xfs_io -x -c 'resblks' /dataA second XFS failure mode is subtle. A new batch of inodes needs a contiguous chunk of free space. On a heavily fragmented, nearly full filesystem, XFS can fail to create files with "No space left on device" even though df shows free blocks and IUse% is low.
Btrfs: allocation in chunks
Btrfs allocates space in large chunks, assigns each chunk to data or metadata, and may store copies of it (for example, RAID1 stores two). Plain df cannot show this clearly. It may report free space that your data cannot use, and df -i is not useful because Btrfs has no fixed inode table.
sudo btrfs filesystem usage /dataRead these values from the output:
- Device size and Device allocated: how much of the disk has been carved into chunks.
- Free (estimated): space you can still write, after accounting for the redundancy profile.
- Metadata
usedversustotal: when metadata chunks are full and no unallocated space remains, writes fail withNo space left on deviceeven though data chunks have room. - Global reserve: space set aside so that metadata operations such as deleting files can still finish.
Snapshots add another trap. Files shared between a snapshot and the live subvolume occupy the same blocks. du counts them again for each path, and deleting a file from the live volume frees nothing while a snapshot still references it.
Choosing the right check
The decision path below summarizes how to approach a "disk full" report once you know the filesystem type.
Effect on the threshold script
The check-disk.sh script from earlier in the tutorial reads Use% and IUse% from df --output=pcent,ipcent,target. Three points follow from this chapter:
- On ext4 with the default reserve,
Use%of 85 means the filesystem is already about 81% full in raw terms. Root-owned services may still write at 100%, so a script run as root can hide a problem that users already see. Alert onUse%, which is the value users experience. - On Btrfs,
df --output=ipcentreturns-. The script converts non-numeric values to 0, so inode warnings never fire. That is correct for Btrfs. Rely onbtrfs filesystem usagefor metadata pressure instead. - On XFS, an alert on
IUse%is useful, but remember that 100% means theimaxpctceiling, not the physical disk.
Common mistakes
- Reading Size minus Used as free space. On ext4 that includes the reserve, so you will overestimate what users can write.
- Setting the reserve to 0 on
/. The next full-disk event then blocks the tools you need to recover. - Running
tune2fson XFS or Btrfs. It only works on ext2, ext3, and ext4. Use the filesystem's own tools. - Planning an ext4 inode increase. You cannot add inodes later. The fix is to back up, recreate the filesystem with more inodes, and restore.
- Trusting
duon Btrfs with snapshots. Usebtrfs filesystem duorbtrfs filesystem usagefor shared extents.
Exercise
A 2 TB ext4 volume mounted at /backup holds only nightly backup files written by a single unprivileged service account. df -h /backup shows Size 1.8T, Used 1.7T, Avail 20G, and Use% 99%. The reserve is at its default. Why is Avail so small, and what is the safest way to get usable space back without growing the disk?
Show answer
Used (1.7T) plus Avail (20G) is well below Size (1.8T). The difference is mostly the 5% root reserve, roughly 90 GB on a 1.8 TB filesystem, which the unprivileged service account cannot use. Since /backup is a data-only volume and no root services depend on it, lower the reserve with sudo tune2fs -m 1 /dev/<device>. This works while mounted and returns about 70 GB to normal users immediately. Confirm with df -h /backup and tune2fs -l. Keep a small reserve instead of 0 to leave the allocator some room, and still plan to expand or prune the volume, because the filesystem is nearly full.
Exercise
A Btrfs volume shows 300 GB free in df -h, but writes fail with "No space left on device". Which command do you run first, and what are you looking for?
Show answer
Run sudo btrfs filesystem usage /mountpoint. Look at the Metadata line to see whether metadata chunks are nearly full, and at "Device unallocated" to see whether any space is left to create new chunks. If metadata is full and nothing is unallocated, the free space in df is locked in data chunks. Rebalancing with a low usage filter (btrfs balance start -dusage=10 /mountpoint) frees underused data chunks so metadata can grow.