Same Error Message, Different Root Cause Every Time
"No space left on device" and "Permission denied" are two of the most common errors on any Linux system, and both are frustratingly generic — the exact same message can mean four or five completely different underlying problems, most of which the obvious first fix (delete some files; chmod 777) doesn't actually touch.
"No Space Left on Device" When There's Clearly Space
$ cp bigfile.tar /var/lib/data/
cp: error writing '/var/lib/data/bigfile.tar': No space left on device
$ df -h /var/lib/data
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 50G 12G 36G 25% /
25% used, 36GB free — and yet the write fails. There are two real causes, and they look identical from the application's point of view.
Cause 1: Inode Exhaustion
Every filesystem has a fixed number of inodes decided at creation time — one is consumed per file, directory, or symlink, regardless of how small the file is. A directory full of millions of tiny files (session files, mail queue items, a runaway node_modules tree, cache fragments) can exhaust the inode pool while barely touching the actual block/byte usage.
df -i /var/lib/data
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/sda1 3276800 3276800 0 100% /
df -h and df -i can tell completely different stories — always check both, because block exhaustion and inode exhaustion produce the exact same "no space left on device" error to every application.
Find what's actually eating the inodes:
find /var -xdev -printf '%h\n' | sort | uniq -c | sort -rn | head -20
This lists which directories contain the most files, which is almost always the fastest way to spot the culprit (a PHP session directory with millions of stale files is a classic case).
Cause 2: Deleted Files Still Held Open
Deleting a file only removes its directory entry — the name pointing at the data. If a running process still has that file open, the kernel keeps the underlying blocks allocated until the last file descriptor referencing it is closed, even though ls can no longer see the file anywhere.
lsof +L1 | grep deleted
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NLINK NODE NAME
rsyslogd 842 syslog 3w REG 8,1 4294967296 0 131074 /var/log/syslog (deleted)
Real case: a log file was deleted directly (instead of properly rotated) to free space quickly, but the service writing to it — rsyslogd, an application logger, anything — kept its file handle open and kept writing into space df now shows as fully used, with no visible file to explain it.
Fix without restarting the service: truncate the file through its still-open file descriptor rather than deleting it again (it's already "deleted"):
: > /proc/842/fd/3
This immediately reclaims the space because the kernel truncates the underlying data while the process keeps its (now empty) file descriptor open. The permanent fix is using logrotate's copytruncate option or sending the service a reload signal after rotation, so it reopens its log file properly instead of writing into a deleted one.