How to Fix ‘No Space Left on Device’ When Inodes Are Full in Ubuntu

Running into the error No space left on device in Ubuntu is a common system administration hurdle. However, confusion arises when you execute df -h to check available disk capacity, and the command reports tens or hundreds of gigabytes of free storage. You cannot write new log files, create documents, or install packages, yet your disk appears nearly empty.

In Linux filesystems (such as ext4), disk capacity is constrained not only by physical storage blocks (megabytes and gigabytes) but also by 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 kernel refuses to create any new files, regardless of how much raw disk space remains. This guide shows how to diagnose and resolve inode exhaustion in Ubuntu.

Verify Inode Usage with df -i

To confirm that inode exhaustion is the cause of your disk write failure, check inode allocation rather than block size:

df -i

Examine the output columns: Inodes, IUsed, IFree, and IUse%. If your root partition (/) or boot partition (/boot) reports 100% in the IUse% column and zero in IFree, your system has run out of index nodes.

Identify Which Directory Contains Millions of Small Files

Inodes are almost always exhausted by processes generating massive numbers of tiny files (such as orphaned session files, unrotated logs, package caches, or mail queues). Run the following one-line shell command from root to count file quantities per top-level folder:

sudo find / -xdev -maxdepth 2 -type d -exec sh -c 'echo -n "{}: "; find "{}" -type f | wc -l' \; | sort -k2 -n

Common culprits include:

  • /var/lib/php/sessions/: PHP session files failing to clean up automatically via cron.
  • /var/spool/postfix/ or /var/spool/mqueue/: Undelivered bounced mail queues.
  • /tmp/: Temporary application locks and session sockets.
  • /var/log/: Uncompressed rotated logs and crash dumps.

Delete Excessive Files Efficiently

When a directory contains hundreds of thousands of files, running standard commands like rm * will fail with the shell error: “Argument list too long”. Instead, use find with the -delete flag to delete files incrementally:

sudo find /path/to/bloated/directory -type f -delete

For example, to purge orphaned PHP sessions older than seven days:

sudo find /var/lib/php/sessions -type f -cmin +10080 -delete

Purge Old Unused Linux Kernels

On long-running Ubuntu servers with automated security updates, old kernel headers and modules accumulate in /boot, frequently exhausting inodes on small dedicated boot partitions:

  1. Check currently installed kernels:
    dpkg --list | grep linux-image
  2. Ensure you do not remove your active kernel:
    uname -r
  3. Remove retired kernels and their associated headers automatically:
    sudo apt-get autoremove --purge
  4. Clean the local APT package archive cache:
    sudo apt-get clean

Verify System Recovery

Once excessive files have been pruned, re-verify your filesystem status:

df -i

The IUse% should now show a healthy percentage (typically under 20%), allowing the operating system to create temporary files, sockets, and databases without write errors.

Get the best tech tips delivered straight to your inbox.

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