Sub topic 2
Blocks and inodes: two separate limits
Assume you are comfortable using a shell over SSH, reading file permissions, using sudo, and following simple command pipelines. This chapter builds the model needed to understand why a filesystem can report free space while refusing to create a file, or report plenty of available inodes while having no room for file contents.
A filesystem tracks two kinds of capacity
A filesystem is the structure that organizes files on a disk or partition. It divides storage into fixed-size units called blocks. File contents consume blocks. A small file might use one block, while a large database consumes many blocks.
The filesystem also stores metadata. Metadata describes a file's owner, permissions, timestamps, size, and where its contents are located. An inode is the record that stores this metadata and pointers to the file's data blocks.
A directory stores names and maps each name to an inode number. Creating a regular file normally needs both:
- At least one available inode for the file's metadata.
- Enough available blocks for its contents.
A filesystem can therefore reach either limit first.
Block exhaustion and inode exhaustion
Block exhaustion is the familiar “disk full” condition. A filesystem may have no blocks available for new data, or it may have only a small amount left for metadata and directory growth. Applications can fail to write logs, databases can stop accepting data, and package updates can fail.
Inode exhaustion happens when the filesystem has no unused inode records. This often occurs on systems that create huge numbers of tiny files. Examples include mail queues, web session files, cache entries, temporary files, and per-request application data.
The following comparison helps distinguish the symptoms:
| Limit | Consumed by | Typical cause | Possible symptom |
|---|---|---|---|
| Data blocks | File contents and filesystem structures | Large logs, backups, databases, media | Writes fail with “No space left on device” |
| Inodes | File and directory metadata | Millions of small files | New file creation fails despite free gigabytes |
A zero-inode filesystem cannot create another file or directory, even if its blocks are mostly empty. A zero-block filesystem may still have unused inodes, but it cannot store more content.
Check both limits
Run these commands against a server:
df -hT
df -ihThe first command reports mounted filesystems, their types, total size, used space, available space, and block-use percentage. The -h option makes sizes readable, and -T includes the filesystem type.
The second command reports inode totals and usage. Its columns commonly include:
Inodes: total inode records.IUsed: inode records in use.IFree: unused inode records.IUse%: percentage of inodes used.Mounted on: the mount point covered by that filesystem.
Read the mount point carefully. /, /var, and /home may be separate filesystems. A full /var filesystem does not necessarily mean the root filesystem is full. A command that writes to /var can fail even when /home has abundant capacity.
Interpreting the failure
Suppose df -hT shows /var at 40% used, but df -ih shows /var at 100% inode use. Removing one large file may release many blocks but only one inode. It will not solve the real problem. You need to locate and remove or control the large population of small files, usually after identifying the responsible service.
If block use is high but inode use is low, investigate large files and directory totals instead. The next step is to use tools such as du and find to identify the consumers before taking cleanup action.
Exercise
A filesystem reports 95% block usage but 12% inode usage. What kind of problem should you investigate first?
Show answer
Investigate large files or directories consuming data blocks. The filesystem has many unused inodes, so a large population of tiny files is less likely to be the primary cause.