Sub topic 4
Reading df -i: inode usage per filesystem
This chapter assumes you can use a Linux shell over SSH, read command output, use sudo, and know what a file, directory, and mount point are. You should also have read the earlier chapters on filesystems, mount points, and the difference between blocks and inodes.
What df -i reports
An inode is a record in the filesystem that stores a file's metadata: owner, permissions, timestamps, size, and pointers to its data blocks. Every file, directory, and symbolic link uses one inode. A filesystem with a fixed inode table can refuse to create new files when the table is full, even if there is plenty of free space.
df -i reports inode usage for each mounted filesystem. Add -h to print large numbers in a readable form, and -T to show the filesystem type.
df -ihTypical output looks like this:
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/sda1 3.2M 412K 2.8M 13% /
tmpfs 992K 604 991K 1% /dev/shm
/dev/sdb1 64M 64M 0 100% /var/mailThe columns
| Column | Meaning |
|---|---|
| Filesystem | The device or source that holds the filesystem. |
| Inodes | The total number of inodes the filesystem has. |
| IUsed | Inodes currently in use. |
| IFree | Inodes still available. |
| IUse% | IUsed as a percentage of Inodes. |
| Mounted on | The directory where the filesystem is attached. |
The last row in the sample output is the case this chapter is about. /var/mail has no free inodes, so it cannot hold another file. Free space, as reported by plain df, could still show 70% available.
Run both views together
Inode checks are only useful next to the space check. Run both and compare:
df -hT
df -ihRead the two outputs row by row, matching on Mounted on. The table below shows how to interpret the combinations.
| Space (Use%) | Inodes (IUse%) | What it usually means |
|---|---|---|
| High | Low | A few large files, such as logs, backups, or database files. |
| Low | High | Very many small files, such as sessions, caches, or mail queue entries. |
| High | High | Both limits are close. Investigate each separately. |
| Low | Low | Healthy. A "No space left" error has another cause, such as a quota or a deleted-but-open file. |
Recognizing the symptom
When inodes run out, applications fail with the same message they use for a full disk:
No space left on deviceThe error code is ENOSPC. It does not tell you which limit was reached. A common mistake is to run df -h, see free space, and conclude the error is something else. Whenever you see ENOSPC and df -h looks fine, run df -i next.
You can reproduce the symptom safely on a small test filesystem, but do not do it on a production system. On a real server, you more often see it indirectly:
- A web application cannot create a session file.
mailor Postfix cannot queue a message.aptordnfcannot unpack a package.- Editors fail when saving a new file, but can still overwrite an existing one.
That last point is a useful clue. Rewriting an existing file reuses its inode and may succeed. Creating a new file needs a free inode and fails.
Filesystems that report no inode counts
Not every filesystem has a fixed inode table. Some report zeros or a dash, and IUse% shows -.
df -ih /boot /mnt/data- Btrfs allocates metadata dynamically, so
df -ireports0for its inode totals and-for the percentage. - XFS also allocates inodes dynamically, but it enforces a ceiling set by the
imaxpctoption.df -ireports real numbers for it, and the percentage reflects the current maximum. - ext4 fixes the inode count when the filesystem is created. This is the case where inode exhaustion is most common.
tmpfsreports an inode limit based on memory size.
Any script that parses df -i must handle - as a non-numeric value. The threshold script later in this tutorial treats it as 0 for that reason.
Checking one path
You do not have to scan every mount. Pass a path and df reports the filesystem that contains it:
df -ih /var/lib/mysqlThis is the fastest way to answer "which filesystem is this directory on, and how full is it?" It also avoids a common error: assuming /var is a separate filesystem when it is part of /.
Limiting the output to real filesystems
On a server with containers or snaps, df lists many pseudo-filesystems. Filter them out by type:
df -ih -x tmpfs -x devtmpfs -x squashfs -x overlayThe -x option excludes a type. If you use Docker, note that each container's overlay mount reports the inode usage of the underlying host filesystem, so it repeats the same numbers many times. Excluding overlay removes that noise.
Selecting your own columns
--output lets you choose columns, which makes output easier to parse:
df --output=source,fstype,itotal,iused,iavail,ipcent,target -x tmpfs -x devtmpfsThe available field names for inode data are itotal, iused, iavail, and ipcent. For space data, they are size, used, avail, and pcent. Use these in scripts instead of cutting columns by position with awk, because the default column layout can change when a device name is long.
Common errors
- Reading the wrong row. Match on
Mounted on, not on position. A full/var/maildoes not mean/is full. - Treating
-as zero usage. On Btrfs,-means "not reported," not "empty." - Looking only at the percentage. A 90% rating on a filesystem with 100 million inodes leaves 10 million free, which can last for months. The same percentage on a filesystem with 100,000 inodes leaves 10,000, which can disappear in minutes. Look at
IFreeand at how fast it changes. - Forgetting bind mounts and overlays, which show the same numbers as the filesystem behind them.
- Assuming deleting a large file fixes an inode problem. It frees blocks and one inode. To free many inodes, you must remove many files.
Where inode counts come from
On ext4, mkfs.ext4 picks the inode count from a ratio: by default one inode per 16 KiB of space, set by the inode_ratio entry in /etc/mke2fs.conf. A 100 GiB filesystem therefore starts with about 6.5 million inodes. If you plan to store many tiny files, you must choose a lower ratio at creation time, using mkfs.ext4 -i 4096 for example. You cannot add inodes to an existing ext4 filesystem without recreating it.
To see the inode count and size of an ext4 filesystem directly:
sudo tune2fs -l /dev/sda1 | grep -i inodeReplace /dev/sda1 with your device. The output includes Inode count, Free inodes, and Inode size.
Diagram: reading the result
The flow below shows how to decide what to do after running df -ih.
Practice
Run these on a test machine and compare the results.
- Run
df -ihand note the filesystem with the highestIUse%. - Run
df -hTand compare itsUse%for the same mount. - Run
df -ih /anddf -ih /tmp. Decide whether/tmpis its own filesystem.
Exercise
A server reports "No space left on device" when an application creates a new file. Running df -h shows the root filesystem at 41% used. What command do you run next, and what result confirms the cause?
Show answer
Run df -ih (or df -i) on the same filesystem. If IUse% is at or near 100% and IFree is 0, the filesystem has run out of inodes. The error is ENOSPC, which is reported for both block and inode exhaustion.
Exercise
df -ih shows 90% inode use for one filesystem with 200 million inodes and 90% for another with 200,000 inodes. Which is more urgent, and why?
Show answer
The one with 200,000 inodes. At 90% it has only about 20,000 free inodes, which a busy application can use quickly. The other still has about 20 million free. IFree and the rate of change matter as much as the percentage.