Mounts and capacity

Diagnose space and inode exhaustion

Separate filesystem block use, directory totals, reserved space, and inode exhaustion when writes fail.

8 minute lesson

~~~

df -h reports allocated filesystem blocks. du totals reachable files under a path. The numbers answer different questions.

When writes start failing with No space left on device, don’t guess. Work through the layers in order.

Which filesystem is actually full?

Start with the exact failing path:

df -h /var
Filesystem           Size  Used Avail Use% Mounted on
/dev/mapper/vg0-var   20G   19G     0 100% /var

Size is the filesystem’s capacity, Used is allocated blocks, Avail is what unprivileged processes can still write, and Mounted on tells you which mount you’re really measuring. Note that Used plus Avail may not equal Size: ext4 reserves a slice (5% by default) for root, so ordinary users hit 100% first.

Blocks, or inodes?

Every file needs an inode, the metadata record that holds its owner, permissions, and block locations. On ext4 the inode count is fixed at format time. Many tiny files can exhaust inodes while bytes remain:

df -i /var
Filesystem           Inodes  IUsed IFree IUse% Mounted on
/dev/mapper/vg0-var  1310720 1310720   0  100% /var

IUse% at 100% means “no space left” errors even though df -h shows free gigabytes. The usual culprit is a runaway directory of session files, cache entries, or undelivered mail.

Find what’s growing

Use targeted du to walk down toward the biggest directory:

sudo du -xh --max-depth=1 /var | sort -h | tail -5

The -x flag stops du from crossing into other mounted filesystems, so you measure only the full one. Repeat one level deeper each time until you find the growth source.

For inode hunts, count entries instead of bytes:

sudo find /var/lib/php/sessions -maxdepth 1 | wc -l

Then use application knowledge; do not delete unknown files from /var blindly. Find the owning service and use its own cleanup mechanism. And if df says full while du finds much less, a deleted-but-open file is holding the space — that’s the next lesson.

Create a capacity checklist that starts with the exact failing filesystem. Include blocks, inodes, largest directories, growth source, and a safe cleanup owner.

Lesson completed

Take this course offline

Get every free book and course as PDF and EPUB files.

Get the download library →