Read

Module 7 · The system, disks and the environment

Disk space: df

df reports how full each mounted filesystem is; learn to read its columns, pick human units, and understand why this VM's root does not even appear.

What you will learn

  • Read the Size/Used/Available/Use% columns of df.
  • Ask about one path instead of the whole system.
  • Recognise tmpfs, devtmpfs and real block devices in the list.

*No space left on device* is one of the few Linux errors everybody meets eventually, and the command that explains it is df, *disk free*. It walks the list of mounted filesystems and, for each, asks the kernel how many blocks exist, how many are used and how many are still available.

The table

~% df
Filesystem           1K-blocks      Used Available Use% Mounted on
devtmpfs                122720         0    122720   0% /dev
tmpfs                   123452         0    123452   0% /tmp
tmpfs                   123452         0    123452   0% /run
~% df -h
Filesystem                Size      Used Available Use% Mounted on
devtmpfs                119.8M         0    119.8M   0% /dev
tmpfs                   120.6M      4.0K    120.6M   0% /tmp
tmpfs                   120.6M         0    120.6M   0% /run

One row per mounted filesystem. Filesystem is the device or the pseudo-device behind it; Mounted on is the directory where it appears in the tree. Between them, the sizes: by default in 1-kilobyte blocks, which is precise and unreadable. -h (human) scales each number to K, M or G, and -m forces megabytes if you want numbers you can add up. Use% is the one to glance at: anything above 90% on a filesystem that receives logs or uploads deserves attention today.

-T adds a Type column: ext4, vfat, iso9660, tmpfs… It is the fastest way to learn what kind of filesystem is behind a path. df -P prints the strict POSIX format, one line per filesystem however long the device name, which is what you want when a script parses the output.

Asking about one path

Give df a path and it reports only the filesystem that path lives on. df -h /tmp answers *how much room is there for temporary files*, and df -h . answers *how much room is there where I am standing*. This matters because space is per filesystem, not per directory: two directories on the same disk share the same free space, while /tmp and /run here are separate filesystems that fill independently.

~% df -h /tmp
Filesystem                Size      Used Available Use% Mounted on
tmpfs                   120.6M      4.0K    120.6M   0% /tmp
~% df -h /root
Filesystem                Size      Used Available Use% Mounted on
df: /root: can't find mount point

What the three rows here are

devtmpfs on /dev is the kernel-managed directory of device files, and tmpfs on /tmp and /run are RAM-backed filesystems: fast, emptied at reboot, and limited to a fraction of memory (half, by default, which is where the 120 MB comes from). When you mount the CD-ROM in lesson 65 a fourth row appears, /dev/sr0, and it will be the only one with a real device behind it: 100% used, because an ISO image is always exactly full.

OptionEffect
dfAll mounted filesystems, 1K blocks
df -hSizes scaled to K/M/G
df -mEverything in megabytes
df -TAdd the filesystem type column
df -h PATHOnly the filesystem containing PATH

Commands in this lesson

CommandWhat it does
dfFree and used space on every mounted filesystem.
df -hHuman-readable sizes.
df -TInclude the filesystem type.
df -h /tmpOnly the filesystem that holds /tmp.
df -PPOSIX one-line-per-filesystem format, for scripts.

Quiz

  1. What does the Use% column measure?

    • CPU used by the disk
    • How full that filesystem is
    • How often the directory is read
    • Memory used by the cache
  2. Why does `df -h /root` fail in this VM?

    • /root does not exist
    • The root filesystem is an initramfs in RAM, not a mounted device, so df cannot see it
    • df needs the -r option for root
    • The disk is full
  3. Which option adds a Type column?

    • -t
    • -T
    • -y
    • -h
  4. Two directories, /var/log and /home, show the same Available value in df. Why might that be?

    • They are on the same filesystem and share its free space
    • df always prints the same number
    • They have the same permissions
    • Both are empty

Practice

  1. Save a human-readable df report of all filesystems to `/root/lab/l63/df.txt`.

  2. Save a df report that includes the filesystem type column to `/root/lab/l63/types.txt`.

  3. The boot CD is mounted at /mnt. Save the df line for that filesystem only, in human units, to `/root/lab/l63/cd.txt`.

Open this lesson in the app to do the tasks in a real Linux machine and have them checked.