Disk Usage and Inodes
Quick answer
df reports filesystem-level capacity; du estimates storage used by selected file trees. They answer different questions. A filesystem may run out of inodes or another resource even when free data blocks remain.
Prepare the practice environment
Run python3 lab-fixtures/storage/setup.py from the extracted root as an ordinary user. Enter the printed fresh private path and check pwd. Use fresh fixtures, Bash with set -e -o pipefail, LC_ALL=C and umask 077. Only disposable regular files may be written. Optional examples require an authorized snapshot VM. Never substitute actual devices or modify mounts, system configuration or active swap. Review the lab guide.
How it works
An inode stores metadata and references to file data. Hard links share an inode. Sparse files contain holes that need not occupy physical blocks, so logical length and allocated space differ. Deleted files held open by processes can consume space invisible to ordinary du traversal. Reserved blocks, snapshots, shared extents, inaccessible directories and mount boundaries also explain differences. GNU df -i reports inode counts where available; not all filesystems have fixed inode pools.
Imagine two names for the same 1 MiB file. Adding a hard link does not allocate another 1 MiB of file data; deleting just one name does not release the inode while the other remains. GNU du normally counts a multiply linked file only once per invocation, whereas apparent size describes logical length. An open file may survive removal of its last name until the final reference is closed. Investigate these differences before deleting anything.
Try the examples
truncate -s 1048576 ./sparse.imgstat -c '%s' ./sparse.imgdu -b ./sparse.imgBoth display logical size; du -b means apparent size in bytes.
Expected stdout:
10485761048576 ./sparse.imgtruncate -s 1048576 ./sparse.imgstat -c '%b %s' ./sparse.img | awk '{if ($1*512<$2) print "allocated smaller than logical"; else print "not sparse here"}'On this fixture the allocated blocks are smaller; other filesystems may differ.
Expected stdout:
allocated smaller than logicaldf --output=avail . | awk 'NR==2 {if ($1 ~ /^[0-9]+$/) print "available blocks reported"}'The numeric value is intentionally not fixed because free capacity changes.
Expected stdout:
available blocks reportedCommon mistakes
Do not add du totals across hard links or snapshots as if all data were unique. Do not delete unknown system files to resolve a full filesystem.
Practice
Create a fresh sparse file, compare du -h and du --apparent-size -h, and use df -i . to inspect inode reporting. Explain why these are different measurements.
Related references
Study: df, du, stat. These are reference names, not deployed links.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Disk usage and inodes — Knowledge Check
Apply storage concepts to synthetic fixtures and VM-only scenarios.
Which reports filesystem capacity?
Which reports apparent byte length?
What can make df larger than visible du?
Can free blocks coexist with inode exhaustion?