Sub topic 3
Reading `df`: Space Used, Available, and Where It Is Mounted
This chapter assumes that you can use a Linux shell over SSH, understand files and permissions, and use sudo. You should also be comfortable reading command output and using pipes.
The df command reports filesystem-level usage. A filesystem is the structure that stores files on a disk, partition, logical volume, or virtual device. A mount point is the directory where Linux makes that filesystem available.
Start with the filesystem view
Run:
df -hTThe -h option uses human-readable units such as GiB and MiB. The -T option adds the filesystem type.
A typical result looks like this:
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda2 ext4 40G 28G 10G 74% /
/dev/sda1 ext4 976M 210M 700M 24% /boot
tmpfs tmpfs 1.9G 0 1.9G 0% /runRead each row as one mounted filesystem.
| Column | Meaning |
|---|---|
| `Filesystem` | Device, volume, or virtual filesystem providing the storage |
| `Type` | Filesystem format, such as `ext4` or `xfs` |
| `Size` | Total filesystem capacity |
| `Used` | Space currently allocated |
| `Avail` | Space available to ordinary users |
| `Use%` | Percentage of space used |
| `Mounted on` | Directory where the filesystem appears |
The root filesystem, mounted at /, contains most of the operating system unless separate filesystems are mounted below it. For example, a file at /var/log/app.log uses the filesystem mounted at /var if /var is a separate mount. Otherwise, it uses /.
Understand the mount point
A path does not tell you which filesystem stores it. Check the path directly:
df -hT /var/log/app.logThis reports the filesystem containing that path. It is safer than assuming that every path under / belongs to the root filesystem.
A mount can hide files that exist in the directory underneath it. If /data is a mount point, files stored in the original /data directory on the root filesystem are hidden while the mount is active. Disk usage for those hidden files still belongs to the underlying filesystem, but commands that traverse /data see the mounted filesystem instead.
Use precise output when scripting
For scripts, avoid parsing the visual layout of default output. Ask df for specific fields:
df --output=source,fstype,size,used,avail,pcent,target -x tmpfs -x devtmpfs -x squashfsThe -x options exclude virtual or read-only filesystems that may not matter for capacity alerts. The exact exclusions depend on the server.
Values can differ slightly from the sum of individual files because filesystems reserve space for metadata, delayed allocation, snapshots, or privileged users. On some filesystems, Avail is lower than the unused blocks suggested by Size - Used.
Exercise
A server shows /dev/sdb1 at 92% usage mounted on /var, while / is only 40% full. Which filesystem should you investigate for a growing application log?
Show answer
Investigate /dev/sdb1, because /var is its mount point and files under /var use that filesystem.