When checking disk usage on a server, you might see plenty of free disk space. However, the server may suddenly stop allowing you to create new files. One possible reason is that the server has run out of inodes.
What is an Inode?
An inode is a data structure Linux file systems use to store information about files and directories. Each file or directory normally uses one inode.
The inode contains information such as:
File type;
File permissions;
File owner and group;
File size;
Creation and modification information;
Location of the file's data on the disk.
The inode does not store the actual filename. Instead, directories associate filenames with their corresponding inode numbers.
In simple terms, think of disk space as how much data the server can store, while inodes determine how many files and directories it can track.
How can a server run out of Inodes?
A server can have free disk space and still run out of inodes. For example, a server containing a few large backup files may use a significant amount of disk space but only a small number of inodes. On the other hand, a server containing millions of tiny files may consume relatively little disk space while using all available inodes.
This commonly happens because of large numbers of:
Cache files;
Session files;
Temporary files;
Log files;
Email messages;
Application-generated files;
Website cache directories;
Old files that are never automatically removed.
Once all available inodes are used, the file system cannot create additional files or directories, even if several gigabytes of disk space remain available.
What happens when Inodes run out?
When no free inodes remain, applications may begin reporting errors such as "No space left on device". This message can be confusing because df -h may still show available disk space. Depending on the server and applications running on it, exhausted inodes can prevent:
New files from being created;
Log files from being written;
Websites from creating cache or session files;
Email from being stored;
Package managers from installing or updating software;
Applications from creating temporary files.
As a result, websites or services hosted on the server may stop working correctly.
How to free Inodes
To free inodes, remove files or directories you no longer need. Common places to investigate include application caches, temporary directories, old session files, unnecessary logs, mail queues, and application-generated data.
Before deleting large numbers of files, make sure you understand what they contain. Removing files from system or application directories without checking them first can cause services to malfunction.
After unnecessary files have been removed, you can check the inode usage again:
df -i. The number of available inodes should increase immediately after you delete the files.
Conclusion
Inodes are an important part of Linux file systems, but they are easy to overlook because most server monitoring focuses on disk space.
