Sub topic 1
Filesystems and mount points: what you are actually measuring
Prerequisites
This chapter assumes you can:
- Use a Linux shell over SSH.
- Read basic output from commands run with
sudo. - Understand files, directories, and permissions.
- Read a short shell pipeline.
You do not need to know how filesystems work internally. This chapter builds that model. Later chapters in this tutorial rely on it.
Why start here
When someone says "the disk is full", the sentence hides a question: which disk, and which part of it? A Linux server rarely has one pool of storage. It has several filesystems attached at different points in a single directory tree. Tools like df report on those filesystems, not on "the disk". If you misread what a number refers to, you will clean up the wrong place and the alert will keep firing.
This chapter explains what a filesystem is, how mount points join filesystems into one tree, and how to see the layout on a real server. The later chapters on blocks, inodes, df, and du all depend on it.
What a filesystem is
A filesystem is the structure a storage device uses to organize data into files and directories. It records which bytes belong to which file, what each file is called, who owns it, and which parts of the device are free.
A raw storage device, such as a disk partition, holds only numbered blocks of bytes. The filesystem turns those blocks into the names and folders you work with. Each filesystem has its own:
- Total capacity.
- Free space.
- Supply of file records (inodes, covered in the next chapter).
- Type, such as ext4, XFS, or Btrfs.
These limits belong to each filesystem separately. A full filesystem at /var does not make /home any fuller. It also means free space elsewhere will not help the full one.
Mount points
A mount point is a directory where a filesystem is attached to the directory tree. Linux has one tree that starts at /. The filesystem that holds / is the root filesystem. Other filesystems are mounted onto empty directories inside that tree.
Suppose /dev/sdb1 is mounted at /var/lib/mysql. Every path under that directory is stored on /dev/sdb1, not on the root filesystem. The path looks like any other, so you cannot tell where a file lives from its name alone.
In the diagram, /etc and /srv are stored on the root filesystem. /var and everything below it, including /var/log, are stored on a second device. /srv/data is stored on a third. Filling /var/log can exhaust /dev/sdb1 while / still has plenty of room.
Listing what is mounted
Two commands show the layout. findmnt prints the mounts as a tree. df prints each mounted filesystem with its type and usage.
findmnt --real
df -hTThe --real option hides virtual filesystems such as proc and sysfs. The df command is covered in detail later. Here you only need its columns to identify what you are looking at.
A typical result from df -hT looks like this:
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda2 ext4 40G 18G 20G 47% /
/dev/sdb1 xfs 100G 71G 29G 71% /var
/dev/sdc1 ext4 500G 120G 356G 25% /srv/data
tmpfs tmpfs 1.9G 1.2M 1.9G 1% /runRead each row left to right:
| Column | Meaning |
|---|---|
| Filesystem | The device or source that holds the data |
| Type | The filesystem format |
| Size | Total capacity of that filesystem |
| Used and Avail | Space in use and space still available |
| Use% | Used space as a share of what is usable |
| Mounted on | The directory where it is attached |
The last column is the one that matters most when you troubleshoot. It tells you which part of the tree each row describes.
Finding which filesystem holds a path
You often start with a path, such as a log file that is growing, and need to know which filesystem it sits on. Give df a path and it reports on the filesystem that contains it.
df -h /var/log/syslog
findmnt --target /var/log/syslogBoth commands answer the question "where does this path live?". Use them before you start deleting anything. If a path is on a different filesystem from the one that is full, removing it will not help.
Virtual and special filesystems
Not every entry in the mount list is a disk. Some filesystems exist only in memory or expose kernel information:
tmpfsstores files in RAM. Examples are/runand often/dev/shm. Its "disk usage" is memory usage.devtmpfsholds device nodes under/dev.procandsysfsexpose kernel data. They report no meaningful space.squashfsis a read-only compressed image. Snap packages use it, and it always appears 100% full.
The 100% reading for a squashfs mount is normal and is not a problem. Any check you write for disk space should skip these types, or it will raise false alarms. The threshold script later in this tutorial does this with -x tmpfs -x devtmpfs -x squashfs.
Mounts that hide files
Mounting a filesystem onto a directory that already has files in it hides those files. They are not deleted. They remain on the underlying filesystem, but no path reaches them while the mount is active.
This causes a confusing case. Suppose a service wrote data to /var/lib/app while /dev/sdb1 was not yet mounted there. The files landed on the root filesystem. Later the device was mounted at that directory. The files are now invisible, but they still use space on /.
In this situation df shows the root filesystem as fuller than du can explain, because du cannot see through the mount. You can inspect the hidden directory with a bind mount:
sudo mkdir -p /mnt/rootview
sudo mount --bind / /mnt/rootview
sudo du -xsh /mnt/rootview/var/lib/app
sudo umount /mnt/rootviewThe bind mount shows the root filesystem as it is, without the filesystems mounted on top of it. The -x option keeps du on that one filesystem. This is a rare case, but it is worth knowing before you spend an hour looking for missing space.
Mounts that fail to appear
The opposite problem also happens. A filesystem listed in /etc/fstab fails to mount at boot, perhaps because the device is missing. Boot continues, and the directory exists but is empty or sits on the root filesystem. Applications then write to the wrong place, and the root filesystem fills.
Check that every expected mount is present:
findmnt /var/lib/mysql
echo "exit status: $?"findmnt exits with status 1 when nothing is mounted at that path. A monitoring check can use that status.
What the numbers measure
Keep these points in mind when you read any usage figure later in the tutorial:
- Every figure belongs to one filesystem, identified by its mount point.
- Space and file records are separate limits on that filesystem.
dfasks the filesystem for its totals.duadds up the files it can reach by walking directories. The two can legitimately differ.- Virtual filesystems do not describe disks.
- A mount can hide files, and a missing mount can send files to the wrong device.
The following chapters build on these points. Blocks and inodes come next, then the commands that read them.
Exercise
A server has /dev/sda2 mounted at / and /dev/sdb1 mounted at /var. The / filesystem shows 40% used and /var shows 98% used. An application writes a large file to /var/log/app/big.log. Which filesystem does the file use, and how would you confirm it with a command?
Show answer
The file is stored on /dev/sdb1, because /var/log/app/big.log is under the /var mount point. Confirm it with df -h /var/log/app/big.log or findmnt --target /var/log/app/big.log. Both report the filesystem that contains the path. Freeing space on / would not help the full /var filesystem.
Exercise
After a reboot, df shows / at 95% used, but du -xsh /var/lib/app shows only 2 MB. The directory /var/lib/app should be a separate mounted device. Give one likely cause and one way to check it.
Show answer
The device may not have been mounted at the time the application wrote its data, so the files went to the root filesystem. Later the device was mounted over the directory and hid them. Check with findmnt /var/lib/app to see whether a mount exists, and use a bind mount of / (sudo mount --bind / /mnt/rootview) to run du -xsh /mnt/rootview/var/lib/app and see the hidden files.