Pages

Topics

Tools

↑↓navigate↵openescclose
All guides

Linux: No space left on device

The error names a filesystem, not the whole disk. Find which mount is full, check inodes and deleted-but-open files, and clear logs, caches and layers.

~4 min readLinux
#linux#disk#df#troubleshooting
Linux disk stack with one full red segment blocking a write crate and an inode grid beside it

Introduction & Quick Summary

A process that worked an hour ago now fails every write:

code
$ echo "x" > /var/log/app/current.log bash: /var/log/app/current.log: No space left on device $ df -h / Filesystem Size Used Avail Use% Mounted on /dev/nvme0n1p1 118G 118G 0 100% /

Quick answer: one filesystem — or its inode table — is full. No space left on device names the mount that holds the file you touched, not the disk as a whole, so a full /var breaks logs while /home still has room.

bash
df -hT # which mount is at 100% df -i # did inodes run out instead of blocks? sudo du -xhd1 / | sort -h | tail -15 sudo lsof +L1 | head # deleted files still held open by a process

Fix according to what those three commands show. Blocks full means find and free real data; inodes full means millions of small files, usually sessions, mail queues or build caches; deleted-but-open files mean the space is already free on disk but still counted, and only restarting or truncating the holder releases it.

This guide covers how Linux accounts disk space, the four distinct ways a filesystem reports itself full, and the cleanup that is safe to automate versus the cleanup that quietly breaks a running service.

Core Mechanics, Signatures & Reproducible Setup

A filesystem has two independent limits: data blocks and inodes (metadata slots, one per file). A write fails with ENOSPC when either is exhausted, when the user's quota is exceeded, or when a temporary filesystem has hit its size cap.

df -h reports blocks; df -i reports inodes. Ext4 reserves 5% of blocks for root by default, so a filesystem can show 100% used and still accept writes from root.

bash
df -hT / # Filesystem Type Size Used Avail Use% Mounted on # /dev/nvme0n1p1 ext4 118G 112G 0G 100% / # ^ used ^ avail ignores the 5% reserve sudo tune2fs -l /dev/nvme0n1p1 | grep -E "Reserved block count|Block count|Inode count"

A reproducible full filesystem without touching the host disk:

bash
mkdir -p /tmp/full && cd /tmp/full dd if=/dev/zero of=big.img bs=1M count=64 mkfs.ext4 -q big.img mkdir mnt && sudo mount -o loop big.img mnt sudo dd if=/dev/zero of=mnt/fill bs=1M count=70 2>&1 | tail -2 # "No space left on device" df -h mnt sudo rm mnt/fill && sudo umount mnt

The same message appears from a write to /tmp when /tmp is a tmpfs sized from RAM, from a Docker container whose overlay layer is capped, and from a Kubernetes pod that has exceeded ephemeral-storage.

Key Comparison Table

ObservationMeaningFirst move
df -h at 100%, df -i lowreal data fills the blocksfind large files under that mount
df -h low, df -i at 100%too many filesdelete small-file directories
df shows space, write still failsdeleted files held openlsof +L1, restart the holder
Only one directory failsquota or a separate mountdf that path, quota -s
Fails on /tmp onlytmpfs or a small tmp partitionclean /tmp, check tmpfs size
Container write fails, host fineoverlay or ephemeral storage capprune images, raise limits
PathCommon causeSafe cleanup
/var/logunrotated logs, journaljournalctl --vacuum-size=500M, rotate
/var/lib/dockerimages, build cachedocker system prune -af
/var/lib/aptcached .deb filesapt-get clean
/home/*/.cachebuild caches, browser dataper-tool cache clean
/var/spoolmail or print queuesinspect, then drain
/tmpstale build artifactsreboot or find -mtime +7 -delete
SymptomInode or blocksProof
Many tiny files (sessions, node_modules)inodesdf -i shows 100%
Few large files (images, backups)blocksdu shows large paths
Space doesn't return after rmneither, held openlsof +L1 lists the file

Practical Edge Cases, Error Fixes & Deep Dive Code Examples

1. Find what is actually using the space

du without -x crosses into other mounts and reports their space as if it belonged to /, which produces nonsense totals:

bash
sudo du -xhd1 / 2>/dev/null | sort -h | tail -15 sudo du -xhd1 /var 2>/dev/null | sort -h | tail -10 sudo find / -xdev -type f -size +1G -printf '%s\t%p\n' 2>/dev/null | sort -n | tail

The -xdev flag keeps the walk on one filesystem, which is exactly what df is measuring.

2. Space that does not come back after rm

A process holding a deleted file keeps its blocks allocated. The directory entry is gone, du reports nothing, and only the kernel knows:

bash
sudo lsof +L1 | awk '$7 > 1000000 {print $1, $2, $7, $9}' | sort -k3 -n | tail sudo truncate -s 0 /proc/1234/fd/7 # release the space without killing the process sudo systemctl restart app # or restart the holder

This is the classic log-file case: a log removed with rm while the service still writes to it. Configuring logrotate with copytruncate avoids it.

3. Inode exhaustion

Millions of 4 KB files fill the inode table long before the blocks are full. Sessions, mail queues, and build directories are the usual sources:

bash
df -i / sudo find /var -xdev -type d -printf '%p\n' -exec sh -c 'c=$(ls -A "$1" | wc -l); [ "$c" -gt 20000 ] && echo "$c $1"' _ {} \; 2>/dev/null | sort -n | tail find /var/lib/php/sessions -type f -mtime +1 -delete

On ext4 the inode count is fixed at mkfs time, so the durable fix is fewer files or a filesystem rebuilt with more inodes — not more disk.

4. journald and logs

/var/log/journal grows without limit on systems without a cap. Journald's own vacuum is safer than deleting files:

bash
journalctl --disk-usage sudo journalctl --vacuum-size=500M sudo journalctl --vacuum-time=14d # persist a cap sudo sed -i 's/^#SystemMaxUse=.*/SystemMaxUse=1G/' /etc/systemd/journald.conf sudo systemctl restart systemd-journald

For application logs, logrotate with size, rotate and compress keeps the directory bounded without manual intervention.

5. Containers and Kubernetes

Inside a container, the writable layer counts against the host unless a volume is mounted. Docker's build cache is often the largest single item:

bash
docker system df docker system prune -af --volumes docker builder prune -af

In Kubernetes, a pod that writes to its own filesystem consumes ephemeral-storage; the kubelet evicts it with Evicted: ephemeral-storage in the pod events, and the node may show space while the pod cannot write.

bash
kubectl describe pod <pod> | grep -A5 "Last State" kubectl get events --field-selector reason=Evicted

Mount an emptyDir with a sizeLimit, or write to a PersistentVolume, so the limit is explicit.

6. Ext4 reserved blocks and quotas

On ext4, only root can use the reserved blocks, which is why a service account fails while sudo succeeds with df at 100%:

bash
sudo tune2fs -m 1 /dev/nvme0n1p1 # lower the reserve from 5% to 1% sudo tune2fs -l /dev/nvme0n1p1 | grep "Reserved block count"

On filesystems with user quotas, the limit is per user rather than per mount:

bash
quota -s sudo repquota -a

The JSON formatter is useful for lsblk -J output when a machine has many volumes and you need to see which one backs a mount, and the regular expression tester helps pull the largest paths out of du output before deleting anything.

Common Compilation/Runtime Mistakes & Version Gotchas

  • Deleting files with rm instead of truncating. A held-open file keeps its blocks; : > file frees them immediately.
  • Running du / without -x. It reports other mounts and leads to deleting the wrong directory.
  • Deleting /var/lib/docker by hand. Docker's metadata and layers then disagree; use docker system prune.
  • Assuming 100% means root can't write. The ext4 reserve keeps root working, which hides the problem from an interactive session while services fail.
  • Clearing /tmp on a live system with rm -rf /tmp/*. Some processes hold sockets and lock files there; delete by age instead.
  • Ignoring inodes. df -h looks healthy while df -i is at 100%, and the error is identical.
  • Forgetting snaps and container images. /var/lib/snapd and /var/lib/containerd grow silently; snap list --all shows old revisions that can be removed.

Official documentation: df(1) and tune2fs(8) reserved blocks.

Official references

primary documentation

The Linux documentation that defines the behaviour this guide explains.

Try matching browser tools

All tools

Small utilities that fit Linux work — they run entirely in this browser tab, so nothing you paste leaves your device.

All Linux guides

More in Linux

All Linux guides

The guides filed next to this one in Linux, in library order.