Linux and networking
Disk space and mounts
"No space left on device" has three different causes, only one of which df -h shows. Also how disks attach to folders with mounts.
A full disk stops a service from writing anything. The error is always the same, "No space left on device", but the cause can be one of three things. df -h only reveals the first. A mount is how a disk, network share or memory-backed filesystem is attached to a folder, so the disk's contents appear under that path.
Walking through it
Start with two commands. df reports each filesystem. du reports how big each folder is.
df -h # free blocks (space) per filesystem
df -i # free inodes per filesystem
du -sh /var/* | sort -h # which folders are bigThen check the three causes in this order:
- Out of blocks.
df -hshows 100%. Usually logs, core dumps or Docker images. Check withdocker system df. - Out of inodes. Every file uses one inode, a fixed metadata record, and the filesystem allocates a fixed number of them when it is formatted. Ten million tiny session files can use them all while
df -hstill shows 60% free.df -ireveals it. - Deleted but still open. A process holds a 50 GB log open. Someone runs
rmon it. The space is not freed, because the process still holds the file.dfsays full, butducannot find the files.lsof +L1lists open files with zero links. The fix is to restart the process, or to empty the file in place with: > app.log.
Mounts are configured in /etc/fstab. On a cloud VM, you typically attach a block volume, format it with mkfs.ext4 or mkfs.xfs, and mount it at /var/lib/<service> so the data survives replacing the machine. Two rules keep the machine bootable:
- Refer to the disk by
UUID=in fstab, not by device name like/dev/nvme1n1, because device names can change between boots. - Add
nofail, so a missing volume does not stop the machine from booting.
Use findmnt to see what is mounted where, and lsblk to see the disks.
Common mistakes
- Deleting a live log file to free space. Truncate it with
: > app.log, or use logrotate'scopytruncate. - Trusting
df -halone. It cannot show inode exhaustion or deleted-but-open files. - Using device names in fstab. Use the UUID.
Check yourself
df -hshows 60% free, but writes fail with "no space left". What do you run next?df -i. The filesystem has run out of inodes.- You deleted a 50 GB log and
dfstill shows the disk full. Why? A process still has the file open. The space comes back when the process closes it.
Key takeaways
- "No space left" can mean blocks, inodes, or deleted files still held open.
- Check
df -h, thendf -i, thenlsof +L1. - Mount volumes by UUID with
nofail, and truncate live logs instead of deleting them.
Further learning
The filesystem layer underneath these numbers is covered in file systems and journaling. The next page covers the rules for running scripts that touch these disks: safe bash scripts.
The Linux Command Line (William Shotts)Linux Command Line Books by William Shottslinuxcommand.orgRelated
Linux for engineers
The parts of Linux you touch in production, from shell pipelines and systemd services to permissions, disks, network debugging commands and safe remote access.
Permissions and capabilities
How Linux decides who can read, write or enter a file, why "permission denied" often comes from a parent directory, and how to grant one power instead of root.
Linux performance analysis
The USE method and the 60-second checklist for finding why a box is slow, covering CPU, memory, disk, network and the container limits that look like application bugs.