Disk Space and Inode Exhaustion on Linux: Diagnose ENOSPC, Reclaim, and Prevent Full Volumes

Last Verified On: Kernel 6.8 / 6.12 LTS / Ubuntu 24.04 LTS & Debian 12/13 Moderate (Service Restart) Exit Code: 1

Direct Answer / TL;DR

Root cause: errno 28 (ENOSPC) fires when a filesystem has zero free data blocks or zero free inodes. Run df -hT and df -i on Ubuntu 24.04, Debian 12, and RHEL 9 to identify which pool is exhausted; reclaim via du drill-down, lsof +L1, journalctl --vacuum-size, and package-cache cleanup; cap growth and alert at 80% to prevent recurrence.

df -hT && df -i

Core Architecture & Mechanics

Linux filesystems account for two independent resource pools through the statfs(2)/statvfs(3) interface: data blocks (f_blocks, f_bfree, f_bavail) and inodes (f_files, f_ffree). Both pools fail writes into the same errno: ENOSPC (28), rendered by glibc as ‘No space left on device’. Because the error text is identical for both, df(1) – the userland renderer of these counters – must be read twice: df -h for the block pool, df -i for the inode pool. A filesystem at 40% block usage and 100% inode usage rejects every tiny-file write just as hard as a truly full one, and cp, dd, or an application traceback gives no hint which pool actually failed.

The inode pool behaves completely differently across the workhorse filesystems. On ext4, the inode table is sized at mkfs time from the -i bytes-per-inode ratio (roughly one inode per 16 KiB by default) and is immutable afterward: no online tool can add inodes, only a rebuild of the filesystem can. XFS allocates inode chunks lazily from free space and caps the share with imaxpct (25% of blocks by default), adjustable online via xfs_growfs -m. btrfs has no fixed inode ceiling at all – its metadata is simply one chunk type among others. Inode exhaustion is therefore predominantly an ext4 symptom driven by millions of small files: session stores, maildir, CI build artifacts, spools under /var/spool and /var/lib.

Block accounting has its own traps. ext4 reserves a fraction of blocks for root – 5% by default, set by mke2fs -r or tune2fs -m. df derives Use% as used / (used + available), where available excludes the reservation, so a full ext4 filesystem reads exactly 100% while root retains free blocks that a non-root daemon cannot touch: the classic ‘root can write, the service cannot’ ticket. XFS, btrfs, overlayfs, and tmpfs have no equivalent reservation. Additionally, the ext4 journal is metadata sized at mkfs and is not reclaimable, and jbd2 writeback can transiently pin large numbers of blocks during fsync storms without any file visibly growing.

unlink(2) removes a directory entry, not the storage. The inode and its blocks persist until the last open descriptor closes or the host reboots, which produces the characteristic df/du divergence: a daemon that lost its logfile path (logrotate with a missing or failing postrotate reload) keeps appending to the now-unlinked inode – invisible to du because no path resolves to it, fully counted by df. Reclamation is binary: restart the holding process, or truncate in place through the live descriptor via /proc/<pid>/fd/<n>. Running rm again or re-running logrotate frees nothing.

On container hosts the accounting moves: Docker and Podman root filesystems are overlayfs with a writable upperdir on the host backing filesystem. df inside a container reports the host filesystem’s counters; deleting read-only image-layer files frees nothing because layers are shared; only upperdir deletions reclaim host space. Real accounting lives under /var/lib/docker (or the Podman storage directory), and docker system df is the only tool that separates images, containers, build cache, and volumes into distinct pools.

Three further distortions skew block numbers. Writes that landed on a path before its device was mounted sit hidden underneath the mountpoint – du walking the merged tree cannot see them, df still counts them; a second bind mount of the live root exposes them. tmpfs (/dev/shm, /tmp on tmp.mount systems) consumes RAM and swap, not disk – ENOSPC on tmpfs predicts OOM, not disk growth. Finally, sparse files make du (allocated blocks) and du –apparent-size (logical bytes) diverge arbitrarily, so every alarm and capacity plan must state which size it compares.

# Baseline triage: read both pools on every mounted filesystem. Never trust one alone.
df -hT && df -i

Complete Reference Table / Diagnostic Matrix

Run the read-only diagnostic column before any destructive reclamation; each row is validated on kernel 6.x with util-linux 2.39+.

Item / Code / FlagBehaviorCommon Cause / Use Case
errno 28 ENOSPCopen/write fails with ‘No space left on device’ when free blocks or free inodes reach zero.The error text is identical for both pools, so df -h and df -i are both mandatory before choosing a fix.
errno 122 EDQUOTWrite fails with ‘Disk quota exceeded’ while physical space remains.Quota masquerading as a full disk; verify with quota -s or xfs_quota report before ordering more storage.
df -hTRenders statvfs block counters plus filesystem type per mount.First triage: locates the full filesystem and its driver (ext4, xfs, btrfs, overlay, tmpfs).
df -iRenders f_files / f_ffree as inode usage (IUse%).Mandatory second read; the classic full-inode ext4 volume shows 40% block use and 100% IUse%.
stat -f <path>Raw one-filesystem counters (f_bavail, f_ffree) from statfs(2).Machine-readable monitoring without df column parsing.
du -xsh <path>Total allocated size under path without crossing mountpoints (-x).Fast consumer localization; compare against df to detect unlinked-fd or shadowed-mount drift.
du -h --max-depth=1 / | sort -rh | head -15Ranked one-level breakdown from the root.Iterative drill-down toward the offending directory tree.
ncdu -x /varInteractive ncurses usage browser.Manual review-and-delete workflow on interactive hosts; absent on busybox-based Alpine by default.
lsof -nP +L1Lists open files with link count &le; 1, i.e. unlinked but still held.Primary tool for deleted-but-open space leakage (NAME column ends in (deleted)).
find / -xdev -type f -size +500M -exec du -h {} +Walks one filesystem emitting files above the size threshold.Largest-offender sweep; always run with -print (or pipe to a file) before any -delete.
journalctl --vacuum-size=200M / --vacuum-time=30dDeletes archived journal segments down to the given bound.Standard reclaim for /var/log/journal; read-only sibling: journalctl –disk-usage.
tune2fs -l /dev/<device>Dumps the ext4 superblock: block counts, reserved blocks, inode count and size.Explains root-only write headroom and the immutable ext4 inode ceiling fixed at mkfs.
xfs_info <mountpoint>XFS geometry including imaxpct.Confirms the online inode-allocation ceiling before raising it with xfs_growfs -m.
btrfs filesystem usage <mount>Per-chunk allocation view (data vs metadata), unlike df totals.btrfs outages are often metadata-chunk exhaustion that df’s raw numbers hide.
docker system dfImage, container, build-cache, and volume accounting for the Docker storage dirs.Maps container churn onto host directories under /var/lib/docker.

Multi-Distro Implementation Differences

statvfs counters are identical everywhere; the divergence is tooling – package-manager cache paths, journal vacuum availability, and busybox applet constraints on Alpine.

Ubuntu / Debian

df -hT && df -i
du -xhd1 / 2>/dev/null | sort -rh | head -15

# Reclaim the APT payload - simulate first, apply second
apt-get -s autoremove --purge      # dry-run: prints planned removals only
apt-get clean                      # deletes /var/cache/apt/archives (destructive)
apt-get autoremove --purge         # destructive: apply only after -s review

# journald - inspect size before trimming (destructive)
journalctl --disk-usage
journalctl --vacuum-size=200M

RHEL / AlmaLinux / Rocky

df -hT && df -i
du -xhd1 /var 2>/dev/null | sort -rh | head -15

# RHEL 9 defaults to XFS on / - check the inode ceiling
xfs_info / | grep -o 'imaxpct=[0-9]*'
tune2fs -l /dev/mapper/almalinux-root | grep -iE 'reserved|inode count'  # ext4 volumes only

# dnf reclaim
dnf clean all                      # deletes /var/cache/dnf (destructive)
dnf autoremove                     # interactive: review the removal list
dnf remove --oldinstallonly        # old kernel slots; current release is kept

journalctl --vacuum-time=30d       # destructive: drop journal older than 30 days

Arch Linux

df -hT && df -i
du -xhd1 /var | sort -rh | head -15

pacman -Qdt                        # orphaned packages - review names first
pacman -Rs <orphan-pkg>            # remove confirmed orphans and unneeded deps
pacman -S pacman-contrib           # provides paccache
paccache -d -rk2                   # dry-run: list keep-2-version candidates only
paccache -rk2                      # destructive: prune /var/cache/pacman/pkg
journalctl --vacuum-size=200M

Alpine / Containers

# busybox userland: typically no ncdu/lsof; df and du are applets
df -h                              # busybox df supports -i; -T varies by build
df -i
du -d 1 / 2>/dev/null | sort -rn | head -15

apk cache clean                    # wipes /var/cache/apk (destructive)
# On --no-cache container images /var/cache/apk is intentionally empty:
# inspect from the host runtime instead - lsof +L1 and /proc/<pid>/fd of the
# container PID expose unlinked-fd leakage inside the container namespace.

Common Failure Modes & Troubleshooting Recipes

Six production patterns cover nearly every ENOSPC ticket. Always complete the read-only step before the destructive one.

1. df full, du small – deleted-but-open descriptors. df -hT shows ~100% on a filesystem whose du total is far lower; a rotated log or leaked temp file is still held open by a process, and rm frees nothing until the last descriptor closes.

df -hT /var                     # ~100% used
du -xsh /var                    # total far smaller than df's used
lsof -nP +L1 | sort -k7 -rn | head -10   # unlinked-but-open, biggest first
# A: clean fix - restart the holder
systemctl restart <offending.service>

# B: no-restart fix - truncate through the live descriptor (moderate risk)
ls -l /proc/<pid>/fd/<fd>       # confirm holder PID and target size first
: > /proc/<pid>/fd/<fd>         # frees blocks instantly; the fd stays valid

2. Writes fail, df -h shows free space – inode exhaustion. Verify with df -i (IUse% at 100%), then drill into the small-file tree; ext4 inodes cannot be added post-mkfs, so reclamation or XFS relief are the options.

df -i /var
for d in /var/* /var/lib/* /srv/* /home/*; do
  [ -d "$d" ] && echo "$(find "$d" -xdev 2>/dev/null | wc -l) $d"
done | sort -rn | head -10

# Cleanup with mandatory dry-run first (Debian path; RHEL uses /var/lib/php/session)
find /var/lib/php/sessions -xdev -type f -name 'sess_*' -mmin +1440 -print    # dry-run
find /var/lib/php/sessions -xdev -type f -name 'sess_*' -mmin +1440 -delete   # destructive

# XFS only: raise the online inode ceiling after checking block headroom
xfs_info /var | grep -o 'imaxpct=[0-9]*'
xfs_growfs -m 40 /var           # moderate: metadata tuning, reduces ceiling later with -m

3. Slow growth of /var/log/journal – uncapped journald. Default journald policies allow many gigabytes; vacuum immediately, then cap persistently with a drop-in.

journalctl --disk-usage
journalctl --vacuum-size=200M --vacuum-time=30d   # destructive: trims archived logs
logrotate -d /etc/logrotate.conf                  # dry-run: shows rotation plan only

mkdir -p /etc/systemd/journald.conf.d
echo '[Journal]' > /etc/systemd/journald.conf.d/size.conf
echo 'SystemMaxUse=500M' >> /etc/systemd/journald.conf.d/size.conf
echo 'RateLimitBurst=1000' >> /etc/systemd/journald.conf.d/size.conf
systemctl restart systemd-journald

Missing logrotate postrotate reload signals are the root cause of pattern 1 recurring on the same box: the daemon keeps writing to the unlinked inode after rotation.

4. Container churn filling /var/lib/docker. Build cache, stopped containers, and dangling volumes converge on one host directory; prune interactively so the preview acts as the dry-run.

docker system df -v                # per-object breakdown
docker system prune                # previews objects, prompts; Ctrl-C aborts (destructive)
docker builder prune               # buildx build cache - largest CI consumer usually
docker volume ls -f dangling=true -q   # review orphaned volumes before removing

5. du/df mismatch without deleted fds – data hidden under a mountpoint. Anything written to a path before its device was mounted stays below the mount; expose the real root with a bind mount.

findmnt -l -o TARGET,FSTYPE,SIZE,USED,AVAIL,USE%
mkdir -p /mnt/realroot && mount --bind / /mnt/realroot
du -xsh /mnt/realroot/var /var    # compare exposed vs merged views
umount /mnt/realroot

6. Space free, inodes free, writes still fail. Check reserved blocks (non-root writers only) and quotas before scaling hardware; EDQUOT (122) and ENOSPC (28) are distinct errnos but quota errors surface as both in application logs.

tune2fs -l /dev/mapper/vg-root | grep -iE 'reserved block|free blocks'
xfs_quota -x -c 'report -h' /var   # XFS per-user/project usage and limits
quota -vs <user>                   # ext4 user quota when mounted with usrquota

Production Hardening & Safety Checklist

Safety Check: Every destructive step in this guide has a listed read-only predecessor – run it, capture output to a file (tar -C /var -czf /root/var-backup-$(date +%F).tgz log before bulk deletion of log trees), and reconcile the list before deleting. For find-based cleanups, replace -delete with -print, review the candidate list, then delete. Metadata changes are reversible (tune2fs -m restored, xfs_growfs -m lowered, drop-in files removed); deleted data is not – treat every -delete, vacuum, and prune as final.

  • Monitor both pools with a cron or systemd timer; alerting only on df -h misses the full-inode class entirely:
df -Ph  | awk 'NR>1 && $5+0 >= 85 {print $6, $5}'   # block threshold 85%
df -iP  | awk 'NR>1 && $5+0 >= 80 {print $6, $5}'   # inode threshold 80%
  • Cap the journal persistently via the journald.conf drop-in shown in recipe 3 and verify the active bound after restart.
  • Age out spool directories with systemd-tmpfiles instead of cron rm; the clean pass runs under systemd-tmpfiles-clean.timer:
echo 'd /var/lib/myapp/spool 0755 root root 14d' > /etc/tmpfiles.d/myapp-spool.conf
systemd-tmpfiles --create /etc/tmpfiles.d/myapp-spool.conf
systemctl status systemd-tmpfiles-clean.timer
  • Reduce ext4 reservation on dedicated data volumes only (reporting, object stores, CI scratch): verify with tune2fs -l first, then tune2fs -m 1 /dev/<data-lv>. Keep 5% or higher on / (moderate: metadata change).
  • Keep LVM growth single-step: pvresize /dev/<pv> then lvextend -r -L +50G /dev/<vg>/<lv> – the -r resizes the filesystem in the same transaction; XFS grows only and cannot shrink, so oversizing is the only protection (never run lvreduce as a space plan).
  • Quota multi-tenant writers with XFS project quotas or ext4 usrquota so one service cannot consume shared backing space.
  • Plan inode headroom at mkfs on ext4 for small-file workloads: mkfs.ext4 -i 8192 halves the bytes-per-inode ratio; after mkfs the ceiling is frozen, so sizing mistakes surface months later as ENOSPC with gigabytes of apparent free space.

Frequently Asked Edge Cases

df reports free space but writes still fail with 'No space left on device' - what causes this besides inode exhaustion?

Three further causes: ext4 reserved blocks withholding space from non-root writers (check tune2fs -l /dev/<device> | grep -i reserved), user/group/project quotas surfacing as EDQUOT (check xfs_quota report or repquota), and tmpfs targets like /tmp or /dev/shm whose capacity is RAM, not disk.

du and df disagree by tens of gigabytes after a cleanup - was the deletion incomplete?

Usually the deletion was fine: either processes still hold deleted files (lsof -nP +L1 shows unlinked-but-open fds; restart the holder or truncate via /proc/<pid>/fd/<n>), or data was written under a mountpoint before its device was mounted - expose the real root with mount --bind / /mnt/realroot and re-run du there.

Can the ext4 inode count be increased after mkfs without a backup-and-restore?

No - the ext4 inode table is fixed at mkfs by the -i bytes-per-inode ratio. Reclaim by deleting small files, or migrate small-file workloads to a filesystem that allocates inodes on demand such as XFS, whose ceiling can be raised online with xfs_growfs -m <percent>.

References & Upstream Docs

  1. Linux man-pages: man 1 df, man 1 du, man 2 statfs, man 3 statvfs
  2. e2fsprogs/xfsprogs: man 8 tune2fs, man 8 xfs_info, man 8 xfs_growfs, man 8 xfs_quota
  3. util-linux: man 8 findmnt
  4. systemd: man 5 journald.conf, man 1 journalctl, man 8 systemd-tmpfiles
  5. kernel.org: Documentation/filesystems/overlayfs.rst

Related Concepts