Skip to content

No space left on device: find and free disk space on Linux

When Linux reports "no space left on device", work through space, inodes, and deleted-but-open files in order to find the culprit and reclaim the disk safely.

When Linux reports No space left on device, start with df -h to find the full mount, then df -i to rule out exhausted inodes, then lsof +L1 to catch a deleted file that a process still holds open. Only after those three checks do you go hunting for big directories with du -xhd1 | sort -h. Working in that order stops you from deleting the wrong thing, or deleting a large file and being confused when the space does not come back.

What you’ll accomplish

  • Identify exactly which mount is full and whether the problem is bytes or inodes.
  • Find the directory or process responsible instead of guessing.
  • Reclaim space safely from journald, package caches, and Docker.
  • Handle the classic case where rm runs cleanly but frees nothing.
  • Know when to stop cleaning and grow the volume instead.

Prerequisites

  • A shell on the affected host. Most of the diagnosis works as a normal user, but reclaiming space in /var, /boot, or from system services needs root or sudo.
  • Knowledge of which mount is affected — the error message rarely names it, so df -h is the first move.
  • du, df, and lsof ship with essentially every distribution. ncdu is a friendlier interactive alternative to du but is not installed by default; on Debian or Ubuntu it is apt install ncdu, on RHEL-family hosts dnf install ncdu. The steps below use plain du so nothing extra is required.

How it works

A filesystem can run out of two independent resources, and both surface as the same No space left on device error. The first is raw bytes — the data blocks are full. The second is inodes — the fixed-size table of file metadata entries that most ext4 filesystems allocate at format time. Each file, directory, and symlink consumes one inode regardless of its size, so a directory holding millions of empty session files or tiny cache fragments can exhaust the inode table while df -h still shows free space. That is why you always check both df -h and df -i.

The second surprise is deleting a file and watching the free space not move. On Linux, disk blocks are released only when the last reference to a file is gone. A reference is either a directory entry (the filename) or an open file descriptor held by a running process. When you rm a log that a daemon is still writing to, you remove the directory entry, but the process keeps its descriptor open — so the inode and every block it points to stay allocated until that process closes the file or restarts. This is extremely common with log files: an application logs to a file, log rotation or a hasty rm deletes it, and the disk stays full because the daemon never let go.

Decision tree for diagnosing a full disk: check df -h for bytes, df -i for inodes, lsof +L1 for deleted-open files, then du to find big directories and reclaim space

Step-by-step

  1. Find the full mount with df -h. The -h flag prints human-readable sizes. Look for the filesystem at or near 100% under Use%.

    df -h
    Filesystem      Size  Used Avail Use% Mounted on
    /dev/sda1        49G   49G     0 100% /
    tmpfs           3.9G     0  3.9G   0% /dev/shm
    /dev/sda15      105M  6.1M   99M   6% /boot/efi

    Here the root filesystem / is completely full. Note the mount point — you will scope the rest of the search to it.

  2. Rule out inode exhaustion with df -i. Same layout, but the columns count inodes instead of bytes. If IUse% is 100% while df -h showed free space, your problem is too many files, not too much data.

    df -i
    Filesystem      Inodes  IUsed IFree IUse% Mounted on
    /dev/sda1      3200000 812004 2387996  26% /
    tmpfs           998000      2  997998   1% /dev/shm

    Inodes here are fine (26%), so this is a bytes problem. If this column read 100%, jump to the inode failure mode in Troubleshooting.

  3. Check for deleted-but-open files with lsof +L1. This lists open files whose link count has dropped below one — files that have been unlinked but are still held open by a process. The SIZE/OFF column shows how much space each is pinning.

    sudo lsof +L1
    COMMAND   PID USER   FD   TYPE DEVICE   SIZE/OFF NLINK   NODE NAME
    nginx    1423 root    5w   REG  253,1 8123456789     0 262547 /var/log/nginx/access.log (deleted)

    That (deleted) marker with NLINK at 0 is the smoking gun: nginx is holding ~8 GB of a log that no longer has a filename. No find or du will show it. The fix is to restart or signal the process (covered in Troubleshooting), not to hunt for a file that has no name.

  4. Find the biggest directories with du. Run it against the full mount, one level deep, sorted so the largest lands at the bottom. The -x flag keeps du from crossing into other mounted filesystems, which otherwise skews the totals.

    sudo du -xhd1 /var | sort -h
    12K     /var/tmp
    4.2M    /var/cache
    38M     /var/spool
    2.1G    /var/lib
    19G     /var/log
    21G     /var

    /var/log is the offender at 19 GB. Repeat one level deeper on whichever directory dominates until you reach the actual files: sudo du -xhd1 /var/log | sort -h.

  5. Reclaim journald space if the logs are the journal. systemd’s journal grows until it hits its own cap, which can be gigabytes. Vacuum it down to a fixed size — this deletes the oldest archived journal files and keeps the rest.

    sudo journalctl --vacuum-size=200M
    Deleted archived journal /var/log/journal/9f0.../system@00061.journal (128.0M).
    Deleted archived journal /var/log/journal/9f0.../system@00062.journal (128.0M).
    Vacuuming done, freed 4.8G of archived journals from /var/log/journal.
  6. Reclaim Docker space if /var/lib/docker is the offender. First see what Docker is holding, then prune what is not in use. docker system df summarizes images, containers, volumes, and build cache.

    docker system df
    TYPE            TOTAL   ACTIVE  SIZE      RECLAIMABLE
    Images          42      6       18.3GB    14.1GB (77%)
    Containers      9       4       1.2GB     820MB (68%)
    Local Volumes   15      3       6.4GB     4.9GB (76%)
    Build Cache     210     0       9.7GB     9.7GB

    Then prune. docker system prune removes stopped containers, unused networks, dangling images, and build cache. Add -a to also remove all unused (not just dangling) images, and --volumes only if you are certain no named volume holds data you need.

    docker system prune -a
    Total reclaimed space: 23.8GB
  7. Clear the package cache if /var/cache is large. On Debian and Ubuntu, downloaded .deb archives accumulate in /var/cache/apt/archives.

    sudo apt-get clean
    (no output on success)

Validate it works

Re-run df -h on the same mount and confirm Avail is now positive and Use% has dropped. Then confirm the service that was failing can write again.

df -h /
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        49G   22G   25G  47% /

Root is down from 100% to 47%. If an application was crash-looping on the full disk, restart it and check its logs are being written again:

sudo systemctl restart nginx && systemctl is-active nginx
active

Troubleshooting

rm ran cleanly but df still shows the disk full. A process holds the deleted file open, so its blocks are not released. Confirm with sudo lsof +L1, note the PID, and restart or signal that process — for a logging daemon, sudo systemctl restart <service> releases the descriptor and the space returns immediately. If restarting is not an option and the process supports it, some daemons reopen their log files on SIGHUP or a logrotate-style signal without a full restart.

df -i shows inodes at 100% but df -h shows free bytes. You have millions of tiny files, not a few large ones. du by size will not find them; count entries instead. Run sudo find /var -xdev -type f | wc -l to confirm the scale, then narrow with for d in /var/*; do echo "$(sudo find "$d" -xdev | wc -l) $d"; done | sort -n. Common culprits are PHP session files, mail queues, and unrotated per-request logs. Delete in batches — find <dir> -type f -delete inside the offending directory — because a single rm * on millions of files can exceed the argument limit.

du totals look inflated or the search wanders onto other disks. Without -x, du descends into every mounted filesystem under the path, so a bind mount or a network share inflates the numbers and sends you chasing space that lives elsewhere. Always pass -x to stay on one filesystem, and scope du to the exact mount df -h flagged.

The disk is so full you cannot even run commands. Some tools need to write a temp file to start, and shell completion or logging can fail. Free a little breathing room first: truncate an active log in place with sudo truncate -s 0 /var/log/<large.log> — this releases blocks without deleting the file, so no process loses its descriptor. With a few hundred megabytes back, the diagnostic commands run normally.

/boot is full but / has space. On many distributions /boot is a small separate mount, and kernel packages pile up old versions there. A failed apt upgrade complaining about /boot usually means this. Remove superseded kernels with your package manager (sudo apt autoremove on Debian/Ubuntu, which keeps the current and one prior kernel) rather than deleting files in /boot by hand — hand-deleting can leave the bootloader referencing a kernel that is no longer there.

When this is the wrong approach

Cleanup buys time; it does not fix a volume that is simply too small for its workload. If you are vacuuming journald or pruning Docker every few weeks to stay alive, the disk is undersized for what the host does, and the real fix is to grow the volume or move the fast-growing directory (/var/lib/docker, a database data directory, an upload store) onto its own larger mount. Recurring 3 a.m. disk-full pages are a capacity decision, not a scripting problem. Set an alert at 80% so you plan the resize on a weekday instead of firefighting it at full.

If this is the kind of work you’d rather never own again, it’s the daily job of Managed Cloud Ops — book an infrastructure review.

For related failure modes, see why the OOM killer took out the wrong process when a full disk and memory pressure hit together, and reading the systemd journal with journalctl for querying what filled the logs. The full option list lives in the journalctl man page and the du man page.