"No space left on device." The application stops, logs are no longer written, sometimes the database refuses writes. There are three possible causes, and they are not handled the same way: files that are too big, files that were deleted but are still open, or no free inode left. I always check them in that order.
To write this article, I reproduced all three cases on a small 20 MB file system mounted in memory on Ubuntu 26.04. The commands are the same on RHEL, Oracle Linux and Debian. Replace /var with the mount point that is full.
1. Which file system is full, and full of what
df -hT df -i
df -hT gives the space and type of each file system. df -i gives the inodes: a file, a directory or a link uses one, whatever its size. If IUse% is at 100%, it is not space that is missing but inodes. Jump to part 4.
On ext4, 5% of blocks are reserved for root by default (819 out of 16,384 on the test volume I created). A disk can therefore show 100% for users while root can still write. sudo tune2fs -l /dev/sdXN | grep -i 'reserved block' gives the actual reserve.
2. What takes the space
sudo du -xh --max-depth=1 /var 2>/dev/null | sort -h
-x stays on the same file system: without it, du walks into other mounts and the result becomes wrong. sort -h sorts human-readable sizes (3K, 200M, 1G) in the right order. Repeat the command on the largest directory until you find the culprit.
To go straight to big files:
sudo find /var -xdev -type f -size +500M -exec ls -lh {} +If ncdu is installed, sudo ncdu -x /var gives the same information interactively.
The usual culprits: application logs without rotation, /var/log/journal, package caches (/var/cache/apt, /var/cache/dnf), old kernels in /boot, container images and volumes in /var/lib/docker or /var/lib/containers, forgotten backups.
3. The space is used but du cannot find it
This is the case that wastes the most time. df says 95%, du adds up far less, and no visible file explains the gap.
The reason: a deleted file is only really freed once no process has it open any more. If someone ran rm on a 12 GB log while the application was writing to it, the name disappears, but the 12 GB stay in use as long as the application runs.
I reproduced it: after rm on a 12 MB file held open by a process, df still showed 12 MB used while du counted 0.
To find these files:
sudo lsof -nP -a +L1 /var
+L1 selects files that no longer have any name on disk, and -a combines that condition with the mount point. Without -a, lsof adds the conditions up instead of intersecting them, and it lists every deleted file on the machine. The output gives the process, its PID, the descriptor (FD) and the size:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NLINK NODE NAME
sleep 1336664 root 3w REG 0,323 12582912 0 4 /mnt/demo/app/logs/big.log (deleted)
If lsof is not installed, /proc gives the same thing:
sudo find /proc/[0-9]*/fd -lname '*(deleted)' -printf '%p -> %l\n' 2>/dev/null
Two ways to free the space:
- Restart the service that holds the file, cleanly. That is the normal fix.
- If you cannot stop it right away, empty the file through its descriptor. With the PID and FD number found above:
sudo truncate -s 0 /proc/1336664/fd/3
In my test, used space went from 12 MB back to 0 immediately, without stopping the process. The file's content is lost: keep this for logs you no longer need.
The real fix comes next: never rm a log that is open. Empty it with truncate -s 0 file.log, or let logrotate do it with copytruncate or a reopen signal.
4. No inodes left
df -i /var sudo find /var -xdev -type f | cut -d/ -f1-4 | sort | uniq -c | sort -n | tail
The second command counts files per directory, three levels deep, and shows the most crowded ones. In my test, after creating 195 small empty files on a file system limited to 200 inodes, touch answered No space left on device while df -h showed 15% used. The same error message, for a different cause.
The usual culprits: PHP sessions, mail queues, application caches that create one file per entry, and temporary directories never cleaned.
5. Get space back safely
Before deleting anything, I look at what I am deleting. These commands go through the tools made for it:
sudo journalctl --disk-usage sudo apt clean sudo dnf clean packages
apt clean empties the downloaded package cache on Debian and Ubuntu, dnf clean packages does the same on RHEL and Oracle Linux. The journal is capped with SystemMaxUse= in /etc/systemd/journald.conf. For old kernels, dnf keeps the last three by default (installonly_limit=3 in /etc/dnf/dnf.conf); on Debian, sudo apt autoremove removes the ones no longer needed.
The procedure, in short
df -hT df -i sudo du -xh --max-depth=1 /var 2>/dev/null | sort -h sudo lsof -nP -a +L1 /var
Too big, deleted but open, or out of inodes. Three causes, three commands to tell them apart. Only once you know which one do you decide what to delete.