Linux Labs

Storage / Stage 2 of 11

Mounting and fstab

Not running Starting usually ~20 s
Leave the lesson

Step 2 of 7 · theory · 5 min

A directory and a mounted volume

Mounting a volume moves no files. It changes what the path shows, and you can check that.

Attaching a filesystem to a directory is called mounting it. The directory that opens onto its contents is the mount point. While the volume is mounted, the path /mnt/lab-data leads to the volume's root. The directory's own files stay on the root filesystem: the volume covers them, and after umount they are visible again. That is what happened to the night report.

The training volume is the image file /srv/storage-lab/disk.img with ext4 inside. A filesystem lives on a block device, such as a disk or a partition. A regular file is not one, so mount attached the image as the loop device /dev/loop0 and mounted that.

findmnt shows what stands behind a directory in two modes:

Command What it shows
findmnt --mountpoint PATH whether anything is mounted exactly at this directory; if not, no output
findmnt --target PATH which filesystem serves the path, even for an ordinary directory

Your home directory has no volume of its own:

bash
findmnt --mountpoint /home/student   # empty: no volume here
findmnt --target /home/student       # TARGET /: the root FS

df -h PATH shows the same as --target: its Mounted on column shows the mount point of the filesystem the path lives on.

Check yourself 1 question

A service writes to /data. findmnt --mountpoint /data prints nothing, while findmnt --target /data shows TARGET /. Where do its files go?

  • An ordinary directory accepts files: that is how the service wrote report-0915.txt at night. Check with ls /data and df -h /data.

  • findmnt --mountpoint /data found nothing: nothing is mounted at /data, so there is no volume there.

  • There is no buffer for an unmounted volume: files land straight in the directory on the root filesystem, and after mount the volume covers them.

While nothing is mounted at /data, it is an ordinary directory on the root filesystem, and the files land there. Once the volume is mounted they end up under it, like the night report at the start of the lesson.

Key points

  • A mounted volume covers the directory's files without deleting or moving them.
  • findmnt --mountpoint checks for a mount exactly at the directory, while findmnt --target and df show the filesystem that serves the path.
Ubuntu 24.04
Loading…