[SOLVED] Error No Space Left on Device with Free Disk Space (Inodes Exhausted in Linux)
The No space left on device error in Linux does not only trigger when storage gigabytes fill up. Every file, symlink, and directory requires a metadata structure known as an inode. If your system generates millions of tiny files (such as PHP session files, mail queue items, or application cache), the filesystem inode table reaches 100% capacity even when df -h reports plenty of free disk space.
Quick Diagnostics
The No space left on device error in Linux does not only trigger when storage gigabytes fill up. Every file, symlink, and directory requires a metadata structure known as an inode. If your system generates millions of tiny files (such as PHP session files, mail queue items, or application cache), the filesystem inode table reaches 100% capacity even when df -h reports plenty of free disk space.
Quick Solution (1 Minute):
- Check if inodes are at 100%:
df -ih- Locate the folder with the highest file density:
sudo du --inodes -d 2 /var | sort -rn | head -n 15
Step-by-Step Solution
-
1
Step 1: Verify Filesystem Inode Utilization
Run
df -ihto inspect the percentage of consumed inodes (IUse% column) instead of byte storage:BASHdf -ihIf the root partition (
/) or/vardisplays 100% under IUse%, your server is out of inodes. -
2
Step 2: Pinpoint the Directory Consuming Millions of Files
To locate which subfolder inside
/varor/tmpis responsible for inode starvation, run:BASHsudo du --inodes -d 2 /var | sort -rn | head -n 15Common culprits include:
/var/lib/php/sessions/(expired PHP session dumps)./var/spool/postfix/maildrop/(bounced automated cron notification emails).- Application micro-cache directories.
-
3
Step 3: Purge Massive File Accumulations Safely
Avoid running
rm -rf *in directories containing hundreds of thousands of files, as bash will abort withArgument list too long. Usefindwith the-deleteflag:BASH# Purge stale PHP sessions older than 24 hours sudo find /var/lib/php/sessions/ -type f -cmin +1440 -delete # Purge compressed historical log archives sudo find /var/log/ -type f -name "*.gz" -mtime +30 -deleteVerify the recovery by re-running
df -ih.
Frequently Asked Questions
Can you increase the inode count on an existing ext4 partition?
On ext4, the inode density is permanently written during partition formatting via mkfs.ext4. To expand inodes dynamically, consider migrating workloads to XFS or Btrfs which allocate inodes on demand.
Why does lsof report deleted files holding inodes?
If an active process keeps a file descriptor open after deletion, the kernel refuses to deallocate the inode. Pinpoint them with lsof +L1 and restart the holding daemon.
Prevention Advice
Recommended security practices:
- Enforce strict log retention policies in
/etc/logrotate.confwith automated compression. - Schedule cron cleanup routines for high-frequency temporary file directories in
/etc/cron.daily/.