Skip to content
Loopedin Labs

No space left on device (ENOSPC)

Writes are failing and the disk claims it's full. Find out why.

Mini Rush · practice

Three questions before you read

Guessing first makes the answers stick. No sign-in.

Several different things run out under the same error. Check which before you delete anything.

What it means

The kernel returned ENOSPC because the write needed a resource that has run out. Usually that resource is data blocks, but not always:

  • Blocks: the filesystem really is full. df -h shows 100%.
  • Inodes: there are too many files. df -i shows 100% even though df -h shows space.
  • Deleted but open: a process still holds a deleted file, so its blocks are never freed.
  • Reserved blocks: ext4 keeps 5% for root, so normal users hit the limit first.
  • Not disk at all: inotify_add_watch returns ENOSPC when fs.inotify.max_user_watches is used up.

Find which one

df -h                      # which mount is full (bytes)
df -i                      # inodes per mount
sudo lsof +L1              # deleted files still held open

Find what's using the bytes, staying on one filesystem:

sudo du -xh / --max-depth=2 2>/dev/null | sort -h | tail -20

Find what's using the inodes, by counting files per directory:

sudo find / -xdev -type f | cut -d/ -f2-3 | sort | uniq -c | sort -n | tail

Check the usual heavy users:

journalctl --disk-usage
docker system df
sudo du -sh /var/lib/docker/containers/*/*-json.log | sort -h | tail

Safe quick wins

sudo journalctl --vacuum-size=500M
docker system prune            # stopped containers, dangling images, build cache
sudo truncate -s 0 /var/log/app/huge.log

For a deleted file that's still open, either restart the process or truncate it through its file descriptor:

sudo truncate -s 0 /proc/<pid>/fd/<fd>

Prevent it

  • Set log rotation for apps, and max-size and max-file for Docker's json-file log driver in /etc/docker/daemon.json.
  • Cap journald with SystemMaxUse= in journald.conf.
  • Alert on both df bytes and inodes at 80%, not 95%.
  • ext4 fixes the inode count at mkfs time. For volumes holding millions of tiny files, use a higher inode ratio (mkfs.ext4 -i) or XFS, which allocates inodes dynamically.
  • In Kubernetes, a full node disk triggers DiskPressure and pod evictions. Set ephemeral-storage limits.

Common wrong fix

Running rm on the biggest log while the app is writing to it. df doesn't change, because the process still has the file open, and now you can't see what's filling the disk. Use truncate -s 0 on live logs, and run lsof +L1 if space doesn't come back. The second trap is rm -rf on whatever looks large under /var/lib/docker. That corrupts Docker's state. Use docker system prune or remove specific images instead.