How to Investigate "No space left on device" Caused by i-node Exhaustion
A summary of how to deal with “No space left on device” when it happens on a Linux server.
First, try df -h
Even with df -h, usage tops out at 77%.
This doesn’t look like something that would cause no space left on device.
1 | $ df -h |
-h = --human-readable, which displays sizes in a human-readable format.
Try df -i
df -i displays i-node information. The maximum is 95%.
This was the culprit.
1 | $ df -i |
Wondering what an i-node is? Take a look at something like the “Seems understandable” / “Not quite” / “Now I get it” IT glossary, i-node edition.
To put it simply, it’s data that manages a file’s attribute information.
In short, as the number of files grows, the data that manages those files grows too, and the number of i-nodes keeps increasing.
Here is a summary of how to investigate it.
Investigate which directory has the most files
The following is a “ranking of directories by file count in the current directory.”
1 | sudo find . -xdev -type f | cut -d "/" -f 2 | sort | uniq -c | sort -r |
- Note: find’s
-xdevoption prevents it from searching mounted filesystems.-type fsearches only files.
Use this one-liner to track down the directories with the most files that are causing the problem.
If you have a hunch, run it in that directory
For example, when there is a separate directory per user, individuals might be running git clone in their home directory, or running bundle install so that the number of files under the vendor directory has exploded.
If something like that seems plausible, it’s a good idea to run the one-liner under the /home/ directory to investigate the cause.
If a particular user is the cause, you can also discuss it with them and confirm whether it’s okay to delete!
The quickest approach is to run it at the root path “/“
To find out which directory has the most files, it’s easier to identify by running from the topmost level, “/“ (root).
However, searching every file in every directory from root consumes a lot of CPU.
After you run it, there’s an anxious wait while it doesn’t respond for a while.
I recommend running it while monitoring the CPU situation with a command like top.
On a production web server, if there’s a chance it will immediately affect users, you’ll want to minimize the scope of impact, for example by temporarily pulling it out of the LB, or by running it during a time with low user access.
Proceed after assessing the situation.
The actual cause of i-node exhaustion I encountered
Under the /usr directory, linux-headers-*** files had piled up, eating up nearly 30%.
The following article saved me. Thank you.
Notes on how to delete old kernels
Addendum 2020-07-02
Regarding deleting linux-headers-*** files, you can remove unnecessary, unused files with the following command.
1 | sudo apt autoremove |
If you want to delete them automatically
1 | // Install the automatic update package |
Edit /etc/apt/apt.conf.d/50unattended-upgrades as follows to add a process that runs autoremove during unattended-upgrade.
1 | sudo vim /etc/apt/apt.conf.d/50unattended-upgrades |
1 | //Unattended-Upgrade::Remove-Unused-Dependencies "false"; |
Logs of automatic updates are output to /var/log/unattended-upgrades/.
That’s all.
How to Investigate "No space left on device" Caused by i-node Exhaustion
https://kenzo0107.github.io/en/2018/10/15/no-space-left-on-device-i-node/
