Short answer: “No space left on device” does not always mean the disk is full of data. On ext4 the filesystem can also run out of inodes, the records that track each file. When that happens, df -h shows free space but nothing new can be created. Run df -i. If IUse% is at or near 100%, you have an inode problem, not a space problem.
Step 1: Compare blocks and inodes
Run both commands on the filesystem that is failing:
df -h /var
df -i /var
df -h counts space. df -i counts inodes. Read the IUse% and IFree columns. This is real output from the Linux machine I used for testing (a container, so it is nowhere near full):
Filesystem Inodes IUsed IFree IUse% Mounted on
overlay 28835840 2205343 26630497 8% /
On a machine with this problem, IUse% would read 100% while df -h still showed free space. I could not fill a real inode table here (it needs root and a spare filesystem), so I am not showing a faked “100%” screenshot.
Step 2: Find the directory with all the files
Inode exhaustion is almost always one directory holding millions of tiny files. GNU du can count inodes instead of bytes:
sudo du --inodes -x -d1 /var | sort -rn | head
The count comes first, then the path. Repeat the command on the biggest path to drill down. I tested this on GNU coreutils 9.1 with a small folder of 8 session-style files and 1 cache file, and it returned 9 and 2 for those two folders (each count includes the folder itself). If your du has no --inodes option, this works on any system:
sudo find /var -xdev -printf '%h\n' | sort | uniq -c | sort -rn | head
It prints how many entries sit directly inside each directory. Both commands can take a while on a large disk. -x and -xdev keep them on one filesystem.
Step 3: Remove what you can safely remove
Only delete what you recognise. Typical sources are old session files, cache folders, and mail or spool queues, but check what the directory belongs to first. Preview before deleting:
find /path/to/dir -type f -mtime +7 | head
find /path/to/dir -type f -mtime +7 -delete
The first command lists files older than 7 days. Run the second only when that list looks right. Using find ... -delete avoids the “Argument list too long” error that rm /path/* gives when a directory holds too many files for the shell to expand. After deleting, run df -i again to confirm that IFree went up.
Why it happens: ext4 sets the inode count when you format
On ext2/3/4, the number of inodes is fixed at creation. The mke2fs manual says it creates one inode for every bytes-per-inode of disk space (option -i), that a larger ratio gives fewer inodes, and that the ratio cannot be changed after the filesystem is created. You can also set the count directly with -N. A partition made for large files can therefore run out of inodes long before it runs out of space if you later store millions of small files on it.
If you keep hitting the limit, the fix is a new filesystem made with a smaller -i value or a higher -N, then restoring the data. Back up first, because reformatting erases the disk.
XFS works differently. It allocates inodes dynamically, but it still caps the share of the filesystem that inodes may use (the maxpct option in mkfs.xfs), so it can also report inode exhaustion.
FAQ
Does “No space left on device” always mean inodes?
No. The message is the standard error for a full filesystem, whatever the cause. Check df -h first for space, then df -i for inodes.
Can I add more inodes to an existing ext4 filesystem?
Not directly. According to the mke2fs manual the ratio cannot be changed after creation, and resizing keeps the same ratio. You must create a new filesystem with different settings.
I see the same error in an Apache log. Is it the same thing?
It can be, but not always. I covered one Apache case in [error] (28) No space left on device: mod_python: Failed to create global mutex. Start with df -h and df -i on the affected path.
Sources
- mke2fs(8) manual page:
-iand-Noptions - mkfs.xfs(8) manual page:
maxpctoption
