Part 2 of 7 · 2 min read
The report
Think of a household whose bank balance is lower than the total of the receipts in the drawer. The gap has a few usual causes: a payment that has not been written down, a promise that holds some of the money back, and a bill that was paid but kept. You check each one in turn. The analogy stops in one place: a bank has one ledger, while a file system has several that can disagree for good reasons.
In plain words: A team reports: "The disk is full. We deleted the old logs and nothing changed, and du cannot find the space." The method is to write down the numbers first, then test each possible cause. There are five usual ones. Blocks are used by files that du can see. Blocks are held by a file that has no name but is still open. A file looks big or small because it is sparse. The blocks are reserved or lost to the file system's own structures. Or the inodes, not the blocks, ran out. Each has a different test.
A worked example. The table lists the causes with the command that tests each.
| Cause | Test | Page of this level |
|---|---|---|
| Large visible files | du -x on the mount, sorted by size |
1 |
| Deleted but open file | ls -l /proc/*/fd, look for (deleted) |
1, 2 |
| Sparse file | compare ls -l and du |
3 |
| Reserved or metadata blocks | tune2fs -l |
2 |
| Out of inodes | df -i |
2 |
The key lines. The first thing to settle is which of two numbers is wrong. df asks the file system how many blocks are used (it calls statfs, page 6). du walks the directory tree and adds up the blocks of the files it finds. When both are right but differ, some blocks are used by something that the walk cannot see.
Disk usage versus file size
The disk usage of a file is the number of blocks that the file system has allocated for it, times the block size. Its apparent size is the length that stat reports in st_size. The two can differ: a sparse file uses less than its size, and a small file uses a whole block.
Example: a file of 1 byte has an apparent size of 1 and a disk usage of 4,096 bytes on ext4 with 4 KiB blocks.
Check yourself:
1. Which of df and du asks the file system for its own count?
2. Name the five usual causes of a full disk.
3. What is the difference between apparent size and disk usage?