Sub topic 3
Reading df: space used, available, and where it is mounted
This chapter assumes you can use a Linux shell over SSH, read command output, and use sudo. It also assumes you know that a filesystem is mounted at a directory called a mount point, and that it has both blocks and inodes. Inodes get their own chapter, so here we only read the space columns.
What df reports
df stands for "disk free". It asks each mounted filesystem how much space it has and prints one row per mount. It does not walk directories and add up file sizes. It reads the totals the filesystem keeps for itself, so it runs in milliseconds even on a huge volume.
That design explains most surprises later. df answers "how full is this filesystem, according to the filesystem?". du answers "how big are the files I can find under this path?". The two numbers can differ, and a later chapter covers why.
The basic command
Run it with human-readable sizes and the filesystem type:
df -hTTypical output on a small server:
Filesystem Type Size Used Avail Use% Mounted on
tmpfs tmpfs 394M 1.1M 393M 1% /run
/dev/sda1 ext4 50G 38G 9.1G 81% /
/dev/sdb1 xfs 200G 120G 80G 61% /var/lib/data
tmpfs tmpfs 2.0G 0 2.0G 0% /dev/shm
/dev/sda15 vfat 105M 6.1M 99M 6% /boot/efiThe columns are:
| Column | Meaning |
|---|---|
| Filesystem | The device or source that backs the mount, such as `/dev/sda1`. |
| Type | The filesystem type. Shown only with `-T`. |
| Size | Total capacity of the filesystem, minus some internal overhead. |
| Used | Space occupied by data and metadata. |
| Avail | Space an ordinary user can still allocate. |
| Use% | Used divided by (Used + Avail), rounded up. |
| Mounted on | The directory where the filesystem is attached. |
Why Used + Avail may not equal Size
On ext4, a slice of the filesystem is reserved for root, by default 5%. Size includes that slice, Used does not, and Avail excludes it. So the three numbers do not add up, and Use% can reach 100% while root still has room. The final chapters on filesystem types return to this.
Why Use% is the number to watch
Use% is computed from Used and Avail, not from Size. This means it describes the space ordinary processes can actually use. A service running as a non-root user fails at 100% Use% even if root could still write. Most services run as non-root, so this is the number that predicts outages.
Units: -h, -H, and -B
By default df prints 1 KiB blocks, which is hard to read. Three options change this:
-huses powers of 1024 (K, M, G). This matches whatdu -handls -lhshow.-Huses powers of 1000 (kB, MB, GB). This matches what disk vendors print on the box.-BGor-B1Mforces a fixed unit, which is useful when you parse output.
Mixing -h from df with -H from another tool is a common source of "the numbers are off by 7%" confusion. Pick one and stay with it.
Reading the mount point column
The last column tells you which directory a filesystem serves. This matters because a full filesystem only affects paths that live on it.
To find which filesystem holds a given path, pass the path:
df -hT /var/logdf prints just the row for the filesystem containing /var/log. If /var is not a separate mount, the row will be the one for /. This is the quickest way to answer "where does this application write, and how full is that place?".
You can also pass several paths:
df -hT /var/log /home /tmpRows can repeat if two paths share a filesystem.
Filtering out noise
A modern server has many virtual filesystems. tmpfs lives in RAM. devtmpfs exposes devices. squashfs holds read-only snap packages and always shows 100% used. Containers add overlay mounts. None of these represent a disk that can fill.
Hide types you do not care about with -x (exclude):
df -hT -x tmpfs -x devtmpfs -x squashfs -x overlayOr show only one type with -t:
df -hT -t ext4 -t xfsFiltering is not cosmetic. If you write an alert that parses all rows, a read-only squashfs at 100% will fire it forever. Exclude those types in the alert, as the later scripting chapter does.
Choosing columns with --output
For scripts, parsing the default layout is fragile because long device names can wrap lines. GNU df lets you pick the columns and their order:
df --output=source,fstype,size,used,avail,pcent,target -hThe available field names are source, fstype, itotal, iused, iavail, ipcent, size, used, avail, pcent, file, and target. A fixed column list gives you the same shape on every run. Add -P (POSIX mode) if you need a single line per filesystem even with long names, though --output cannot be combined with -P.
Reading the output in practice
Consider the sample above. The root filesystem / is at 81%, and /var/lib/data is at 61%. Which one needs attention? Look at three things:
- The percentage. 81% is not an emergency, but a small filesystem fills fast.
- The absolute space. 9.1G available on a volume that receives 1 GB of logs a day is nine days of runway. The same percentage on a 2 TB volume is hundreds of gigabytes.
- Who writes there. Root holds the OS, logs, and package caches. A full root can stop logins, package installs, and
sshdlogging.
Percentage alone misleads. A 95% full 4 TB volume still has about 200 GB free, while a 90% full 10 GB volume has 1 GB.
Bind mounts, btrfs, and duplicate rows
Some setups show the same storage more than once.
- A bind mount makes a directory appear at a second path. Both rows show the same numbers, so do not add them together.
- Btrfs can show several subvolumes mounted from one pool, such as
/and/home, all with identical Size, Used, and Avail. The pool is shared. - Containers show an
overlayrow whose numbers come from the host filesystem underneath.
To avoid double counting, remember that Size totals only make sense per underlying device. Use df --total only on a filtered list, and read the total row with care:
df -h --total -x tmpfs -x devtmpfs -x squashfsCommon errors and how to read them
| Symptom | Likely cause |
|---|---|
| `df` hangs and never prints | A stale network mount (NFS, CIFS) is not answering. Try `df -l` to list local filesystems only, or `timeout 5 df -h`. |
| `df: /mnt/x: No such file or directory` | The path does not exist or was unmounted. |
| A mount you expect is missing | It failed to mount at boot. Check `findmnt` and `/etc/fstab`. If the mount is missing, writes land on the parent filesystem, which can fill it. |
| `Use%` is 100% but `Avail` is not 0 | You read a rounded value, or the filesystem is a type with special accounting. Compare the raw bytes with `df -B1`. |
| Rows for `/dev/loop*` at 100% | Snap or similar read-only images. Exclude `squashfs`. |
The missing-mount case deserves attention. If /var/lib/data should be a separate disk but failed to mount, the directory still exists on the root filesystem. Applications write there happily, and / fills with data that you will later see "disappear" when the real disk is mounted over it. Always check that important paths show the expected Filesystem value in df.
A short diagnostic flow
The diagram shows how to move from a df reading to a next step.
Practical habits
- Run
df -hTfirst whenever a server misbehaves with errors like "No space left on device". - Always read the
Mounted oncolumn before concluding anything. - Record
UsedandAvailin bytes (df -B1) when you want to compare readings over time. - Treat
Use%as a signal andAvailas the budget.
Exercise
On a server, df -hT /var/lib/app shows /dev/sda1 ext4 50G 47G 0 100% /, but Size minus Used is 3G. Why does Avail show 0, and which users still can write?
Show answer
ext4 reserves a percentage of blocks (5% by default, which is 2.5G of 50G) for root. Avail excludes that reserve, so ordinary users see 0 free even though about 3G remains. Processes running as root can still write into the reserved space, but a service running as a non-root user fails with "No space left on device". Also note that /var/lib/app is on /, so the data path shares the root filesystem.
Exercise
Write a command that prints only the source, mount point, and percent used for real filesystems, hiding tmpfs, devtmpfs, and squashfs.
Show answer
df --output=source,target,pcent -x tmpfs -x devtmpfs -x squashfs