Why Your Disk Shows Space Yet Fails: Understanding and Fixing Inode Exhaustion
The article explains what inodes are, why they can become fully consumed even when disk space remains, how to monitor inode usage with df -i, and provides practical steps and command‑line scripts to locate offending directories, delete excess files, and prevent future inode exhaustion on Linux systems.
1. Introduction to inodes
In Linux, file data is stored in blocks, while metadata such as owner, creation date, and size is stored in a structure called an inode (index node). During formatting the disk is divided into a data area and an inode table that holds these metadata entries.
Each inode typically occupies 128 bytes or 256 bytes, and the total number of inodes is set at format time (often one inode per 1 KB or 2 KB). For example, on a 1 GB disk with 128‑byte inodes and one inode per 1 KB, the inode table would consume about 128 MB (12.8% of the disk).
2. Inodes exhaustion
When all inodes are used, the system cannot create new files even if there is still free disk space. This usually happens when many small files fill the inode table.
Disk space may be partially used while inodes are already at 100 %.
Use df to view disk usage and df -i to view inode usage.
Both commands support the -h flag ( df -h and df -hi). In the example, disk space is at 71 % but inodes are at 100 %.
3. Solving inode exhaustion
The size of inodes is determined when the partition is formatted; larger partitions have larger inode tables.
The root partition is often small, so frequent creation of small files without timely cleanup can quickly fill inodes.
Steps to resolve inode exhaustion:
(1) Find directories with the most files for i in /*; do echo $i; find $i | wc -l; done If the range is known, replace /* with a more specific path.
The investigation revealed that /var/spool/postfix/maildrop contained many small files because cron output and warnings were being mailed, but sendmail/postfix failed, causing the files to accumulate.
A per‑minute cron job also generated a small file each minute.
(2) Delete large numbers of files
ls | xargs -n 1000 rm -rf # use xargs to avoid deletion failures4. Summary
(1) Add MAILTO="" as the first line in crontab -e to stop mail files from being created.
(2) Redirect output of cron jobs that do not need logs to /dev/null: */10 * * * * /tmp/test.sh >/dev/null 2>&1 (3) Periodically clean old files, e.g.:
find <directory> -type f -mtime +30 | xargs -n 1000 rm -f(4) Monitor inode usage regularly.
Note: Pay attention to crontab syntax and ensure timely cleanup of generated files.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
