Sub topic 4
Reading `df -i`: Inode Usage per Filesystem
Assume you can use a Linux shell over SSH, understand files and directories, and know how to use sudo. You should also be comfortable reading command output and using pipes.
What an inode measures
An inode is a filesystem record that stores metadata about a file or directory. It includes information such as the owner, permissions, timestamps, file type, and pointers to the file's data blocks.
A filesystem has a limited number of inodes. Every new file and directory normally needs an inode. Therefore, a filesystem can run out of inodes even when it still has free disk space.
For example, a server that stores millions of small cache files may use almost all its inodes while using only part of its available disk space.
df -i reports inode usage for each mounted filesystem:
df -iTypical output looks like this:
| Filesystem | Inodes | IUsed | IFree | IUse% | Mounted on |
|---|---|---|---|---|---|
| `/dev/sda2` | 6,553,600 | 420,100 | 6,133,500 | 7% | `/` |
| `/dev/sdb1` | 65,536,000 | 64,225,000 | 1,311,000 | 98% | `/var` |
The columns mean:
Inodes: the total inode capacity of the filesystem.IUsed: the number of allocated inodes.IFree: the number of unused inodes.IUse%: the percentage of inodes in use.Mounted on: the directory where the filesystem is available.
The Filesystem column identifies the device, logical volume, network filesystem, or virtual filesystem being measured.
Reading percentages and mount points
The command reports one row per filesystem, not one row per directory. The /var/log directory might be on the root filesystem, or /var might have its own mounted filesystem. Check the Mounted on column before deciding which filesystem is affected.
Use human-readable values when the inode count is large:
df -ihTo inspect the filesystem that contains a particular path, provide that path:
df -ih /var/logThis does not measure only /var/log. It reports the filesystem containing that path.
A high IUse% means the filesystem is close to its file-count limit. At 100%, programs may fail to create files, directories, sockets, or temporary files. Existing large files can continue to grow if free data blocks remain.
How inode exhaustion happens
The usual cause is a very large number of small files. Common examples include:
- Mail queues with one file per message.
- Application session files.
- Package-manager or web caches.
- Temporary files that are never removed.
- Per-request logs or task results.
- Container or build-system layers.
The relationship is:
A filesystem with high inode usage requires a file-count investigation. Use du and find to locate directories containing many entries. Do not delete files based only on their age or name until you know which service owns them.
Exercise
df -h shows 30% disk space used, but df -i shows 99% inodes used. What problem is most likely occurring?
Show answer
The filesystem contains a very large number of files, probably small files such as cache, session, queue, or temporary files. New file creation may soon fail even though data blocks remain.