How to Fix ‘No space left on device’ When Disk Free Space Exists (Inodes Exhaustion) in Linux

Executing a file write, saving a document, or starting a container in Linux only to encounter the fatal error: ‘No space left on device’—even though checking df -h reveals gigabytes or terabytes of available disk capacity—is one of the most baffling system administration issues. In Unix and Linux filesystems (such as ext4), disk space is tracked in two distinct ways: physical data storage blocks and inodes (index nodes). Every individual file, directory, and symbolic link consumes exactly one inode. When all pre-allocated inodes on a filesystem partition are exhausted, the Linux kernel refuses to create any new files, regardless of how much physical gigabyte storage remains vacant.

Why Does Inode Exhaustion Occur in Linux?

Filesystems like ext4 set a fixed number of inodes when formatted. Inode exhaustion is typically caused by millions of tiny files accumulated by background applications:

  • Unpurged Web Application Session Files: PHP session files accumulating millions of zero-byte tokens in /var/lib/php/sessions/.
  • Mail Queue Spooling Loops: Undelivered bounce emails flooding /var/spool/postfix/ or /var/spool/mail/ with individual messages.
  • Accumulated Package Manager Cache / Headers: Hundreds of thousands of orphaned C header files or cached deb/rpm packages.
  • Docker Container / Overlay2 Orphan Layers: Unpruned stopped containers, dangling images, and build caches exhausting overlay filesystem inodes.
  • Micro-Log Generators: Unrotated monitoring logs or temporary files written into /tmp/ without automated cleanup.

Step 1: Verify Inode Exhaustion with df -i

Confirm whether inodes are at 100% capacity across your mounted partitions.

  1. Open your terminal.
  2. Run the inode disk filesystem command:
    df -i
  3. Inspect the output columns: Inodes, IUsed, IFree, and IUse%.
  4. Look for any filesystem partition showing 100% in the IUse% column (frequently root / or /var). If IFree is 0, inode exhaustion is confirmed.

Step 2: Locate the Directories Containing Millions of Files

Isolate which specific directory tree is hoarding inodes using find.

  1. Run a find script to count files per top-level directory in the exhausted mount:
    sudo find /var -xdev -printf '%h\n' | sort | uniq -c | sort -k 1 -n | tail -n 15
  2. Review the output list: the number on the left indicates the file count, and the path on the right indicates the folder.
  3. Common culprits include:
    • /var/lib/php/sessions/
    • /var/spool/postfix/maildrop/
    • /var/lib/docker/overlay2/
    • /tmp/

Step 3: Safely Delete Millions of Files Without Argument List Too Long

Running standard commands like rm -rf * inside a folder with hundreds of thousands of files fails with ‘Argument list too long’. Use find -delete instead.

  1. To delete orphaned session files older than 7 days:
    sudo find /var/lib/php/sessions/ -type f -name 'sess_*' -mtime +7 -delete
  2. To delete an entire directory of millions of files without expanding shell arguments:
    sudo find /path/to/bloated_folder/ -type f -delete
  3. Alternatively, purge maildrop spools:
    sudo postsuper -d ALL       # If using Postfix

Step 4: Prune Docker Inodes and Build Caches

If Docker container layers are consuming your inodes, run Docker system cleanup routines.

  1. Prune all unused containers, networks, and images:
    docker system prune -a --volumes -f
  2. Purge buildx cache:
    docker builder prune -a -f
  3. Re-check inode availability:
    df -i /

Step 5: Configure Automated Log and Session Cleanup (cron / systemd)

Prevent future inode starvation by enabling automated maintenance timers.

  1. Verify that systemd-tmpfiles-clean.timer is enabled:
    systemctl status systemd-tmpfiles-clean.timer
  2. Ensure logrotate is configured for applications that generate high file turnover.

Monitoring inode usage with df -i, identifying file-dense directories with find, and purging millions of orphaned files via -delete resolves the ‘No space left on device’ inode exhaustion error in Linux.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.