Linux4 min read· 3 practice problems

No space left on device — causes and fixes (disk space, inode exhaustion, deleted open files)

When you get No space left on device: how to tell full disk space from inode exhaustion, find the big directory, free space held by deleted but still open files, clean up journald and Docker, and stop it recurring with logrotate.

On this page
  1. Short answer: the filesystem has no room left, in blocks or in inodes
  2. First check: space or inodes?
  3. Cause 1: find the big directory
  4. Cause 2: inode exhaustion
  5. Cause 3: deleted, but the space never came back
  6. Cause 4: journald and Docker
  7. What not to do
  8. The order to work in
  9. Quick diagnostic checklist

Short answer: the filesystem has no room left, in blocks or in inodes

No space left on device is the kernel error ENOSPC (errno 28). Usually the disk is full, but it also appears while df -h shows free space. The cause is almost always one of four:

  1. Large files or directories used up the space — logs, dumps, backups, build output
  2. Out of inodes — space is left, but there are millions of small files
  3. Deleted files that are still open — you ran rm and nothing came back
  4. journald or Docker grew quietly — /var/log/journal, /var/lib/docker

First check: space or inodes?

df -h /var
df -i /var
Filesystem      Size  Used Avail Use% Mounted on
/dev/nvme0n1p1   50G   28G   20G  59% /
Filesystem       Inodes   IUsed IFree IUse% Mounted on
/dev/nvme0n1p1  3276800 3276800     0  100% /
  • Use% at 100% → a space problem (causes 1, 3 and 4)
  • Use% has room but IUse% is 100% → an inode problem (cause 2)

Match the failing path to its filesystem (Mounted on) first. Often / has room while a separately mounted /var or /tmp is full.

Cause 1: find the big directory

du -xh --max-depth=1 / 2>/dev/null | sort -h | tail -5
du -xh --max-depth=1 /var 2>/dev/null | sort -h | tail -5

-x keeps du on one filesystem. Step into the largest directory one level at a time, and check what writes there before deleting anything.

Cause 2: inode exhaustion

du --inodes -x --max-depth=1 /var 2>/dev/null | sort -n | tail -5

This points at a directory where small files pile up: sessions, caches, a mail queue. Clean them up and fix what creates them (a missing cleanup cron, a cache with no expiry). On ext4 the inode count is fixed when the filesystem is created, so reducing the files comes first.

Cause 3: deleted, but the space never came back

If a process still has a file open, rm only removes the name; the space is freed when the process closes it. A big gap between the du total and df usage means this case.

lsof +L1
COMMAND  PID USER FD TYPE DEVICE    SIZE/OFF NLINK   NODE NAME
java    2314 app  7w  REG  259,1 21474836480     0 131090 /var/log/app/app.log (deleted)
# restart the process that holds it
systemctl restart app
# or, if you cannot restart, empty the open file (PID 2314, FD 7)
truncate -s 0 /proc/2314/fd/7

truncate frees the space at once, but if the process did not open the file in append mode, its next write continues at the old offset and leaves a sparse file with an empty head. A restart is cleaner when you can afford it.

Cause 4: journald and Docker

journalctl --disk-usage
journalctl --vacuum-size=500M      # permanent cap: SystemMaxUse= in /etc/systemd/journald.conf
docker system df
docker image prune -a              # remove images no container uses
docker builder prune               # remove the build cache

If app logs were the cause, prevent a repeat with logrotate: for an app that keeps its log open, use copytruncate or make it reopen logs in postrotate. Dry-run with logrotate -d /etc/logrotate.d/app.

What not to do

  • rm on a log that is still being written — no space comes back and the log is gone. Empty it with truncate -s 0.
  • Running docker system prune -a --volumes without checking — deleting volumes means deleting data.
  • Deleting files in a database data directory (binary logs, WAL) by hand — use the database's own commands.

The order to work in

  1. df -h and df -i: space or inodes, and on which mount
  2. Narrow down the big directory with du -xh --max-depth=1
  3. If du and df disagree, run lsof +L1 → restart the holder or truncate
  4. Clean up journald, Docker and logs; prevent a repeat with logrotate and size caps

To practise the same situation as a problem, start with the one-minute quiz No space left on device: the disk is full and files cannot be written.

Quick diagnostic checklist

  • Use df -h and df -i to tell a full disk from inode exhaustion.
  • Check which mount (Mounted on) the failing path belongs to.
  • Narrow down the largest directory one level at a time with du -xh --max-depth=1.
  • If inodes are at 100%, find the directory full of small files with du --inodes -x.
  • If du and df disagree, look for deleted but open files with lsof +L1.
  • Free an open file by restarting its process or with truncate -s 0, not with rm.
  • Check hidden usage with journalctl --disk-usage and docker system df.
  • Prevent a repeat with logrotate and the journald SystemMaxUse= cap.

Practice with this guide

Reviewed problems about the same failure. Write the cause, recovery, and prevention yourself, then compare with the model answer.

Read next