How to Fix Inode Exhaustion Errors in Linux
An inode exhaustion error occurs when a Linux filesystem runs out of available index nodes, preventing the creation of new files even if physical storage space remains available. This article explains what inodes are, how inode exhaustion causes the misleading "No space left on device" error, how to diagnose the issue using Linux command-line utilities, and the exact steps required to locate and delete the excess files causing the problem.
What is an Inode and Inode Exhaustion?
An inode (index node) is a data structure on Unix-style filesystems that stores metadata about a file or directory, such as its size, ownership, permissions, and physical location on the disk, but not its content or filename.
When a standard filesystem (such as ext4) is created, a predetermined
number of inodes is allocated based on the total drive capacity. Every
file, directory, symlink, or socket consumes exactly one inode. Inode
exhaustion happens when thousands or millions of tiny files—such as
cache entries, temporary files, or email queues—consume all available
inodes. When the inode table reaches 100% capacity, the operating system
throws a "No space left on device" error, halting write operations,
services, and system updates, even if df -h shows plenty of
gigabytes remaining.
How to Diagnose Inode Exhaustion
To confirm whether an inode shortage is causing system errors, check the inode usage across all mounted filesystems:
df -iLook at the IUse% column in the output:
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/sda1 3276800 3276800 0 100% /
If any filesystem displays an IUse% of 100%, that
partition can no longer index new files.
How to Find Directories with the Most Inodes
Once the affected filesystem is identified, locate the specific directories storing millions of small files. Run the following command from the root or the mounted path to count files inside each top-level directory:
find / -xdev -printf '%h\n' | sort | uniq -c | sort -k 1 -nAlternatively, to scan directory-by-directory without heavy memory overhead, use:
for d in /*; do echo -n "$d: "; find "$d" -xdev | wc -l; doneDrill down into the directories reporting the highest counts. Typical culprits include:
/var/spool/postfix/maildropor/var/spool/clientmqueue(undelivered mail)/var/lib/php/sessions(abandoned web sessions)/tmpand/var/tmp(stale temporary files)/var/log(unrotated logs or millions of trace files)- Node.js
node_modulescaches or application-specific file caches
Resolving Inode Exhaustion
1. Safely Delete the Excess Files
When a single directory contains hundreds of thousands of files,
standard wildcards like rm -rf * fail with an
Argument list too long error. Use find with
the -delete action or xargs to process files
in batches.
To delete older temporary session files:
find /var/lib/php/sessions -type f -name "sess_*" -deleteTo delete files older than 7 days in a cache directory:
find /path/to/cache -type f -mtime +7 -delete2. Clear Unused System and Package Files
On Debian/Ubuntu systems, old Linux kernels consume substantial inode allocations:
sudo apt-get autoremove --purgeOn RHEL/CentOS systems:
sudo dnf autoremoveClear package manager caches:
sudo apt-get clean # Debian/Ubuntu
sudo dnf clean all # RHEL/CentOSHow to Prevent Future Inode Exhaustion
- Configure Log Rotation: Ensure
/etc/logrotate.confis properly rotating and compressing logs, and that log files with excessive entries are cleaned up regularly. - Automate Housekeeping: Implement cron jobs or systemd timers to regularly purge application session files, mail spools, and temporary directories.
- Choose Dynamic Filesystems: When provisioning new servers with workloads that generate high file counts, consider filesystems like XFS or Btrfs, which allocate inodes dynamically as needed rather than relying on a fixed static table.
- Tune Ext4 at Creation Time: If using ext4 for an
application handling millions of small files, increase the inode density
during formatting using the
-ior-Nflag (e.g.,mkfs.ext4 -i 4096 /dev/sdb1).