Mounting and unmounting filesystems

Attaching filesystems to the tree: the mount command, the fstab entries that make it happen at boot, and why devices are named by UUID rather than by /dev path.

Lesson 3 of 6 in objective 104. Devices, Linux filesystems, filesystem hierarchy standard, part of LPIC-1 Exam 101-500.

The six fields of an /etc/fstab line. UUID=8f3a /home ext4 defaults 0 2 — part 1, UUID=8f3a: what to mount. Not /dev/sdX: those are numbered in detection order; part 2, /home: where to mount it; part 3, ext4: the filesystem type; part 4, defaults: options: noauto, ro, user, noexec, nosuid; part 5, 0: dump. Effectively always 0; part 6, 2: fsck pass: 1 for root, 2 for others, 0 to skip. 1 UUID=8f3a 2 /home 3 ext4 4 defaults 5 0 6 2 1 what to mount. Not /dev/sdX: those are numbered in detection order 2 where to mount it 3 the filesystem type 4 options: noauto, ro, user, noexec, nosuid 5 dump. Effectively always 0 6 fsck pass: 1 for root, 2 for others, 0 to skip
The six fields of an /etc/fstab line.

mount, and what fstab adds

mount DEVICE DIRECTORY attaches a filesystem at a mount point; umount detaches it, addressed by either the device or the mount point. A umount that reports the target is busy means a process has a file open there or a shell is sitting in the directory — lsof or fuser names the culprit, and cd out of it is usually the whole fix. mount with no arguments lists what is mounted; findmnt shows the same as a tree.

/etc/fstab is the table consulted at boot and whenever mount is given only one of the two arguments. Six fields: what to mount, where, the type, the options, a dump flag that is essentially always 0, and the fsck pass order — 1 for root, 2 for other filesystems that should be checked, 0 for those that should not. A syntax error here can stop a machine booting, which is why it is worth running mount -a before rebooting.

Names that do not move, and options that matter

Device names like /dev/sdb1 are assigned in detection order, so adding a disk can renumber the others and an fstab full of them mounts the wrong things. UUIDs and labels do not move: blkid prints both, and an fstab line reads UUID=… or LABEL=… in the first field. On systemd systems fstab is not a competing mechanism at all: systemd-fstab-generator turns each line into a mount unit at boot, which is why systemctl can say why one failed and why fstab options like noauto and nofail keep working. Writing such a unit yourself instead means naming it after its mount point, because systemd derives the two from one another — /srv/data becomes srv-data.mount, the leading slash dropped and every remaining one turned into a dash — and a unit whose own Where= does not match its file name is rejected. systemd-escape -p --suffix=mount /srv/data produces the name mechanically, which is what you want as soon as a path contains a character needing an escape of its own.

The options field carries the behaviour. defaults is not a special mode but shorthand for seven ordinary options — rw, suid, dev, exec, auto, nouser, async — which is also why defaults,ro,noexec is idiomatic rather than contradictory: options are applied left to right, so the two on the right tighten what defaults had just granted. noauto means "do not mount at boot but allow it later", user lets a non-root user mount it, ro mounts read-only, and noexec, nosuid and nodev restrict what may be done with files on it — the standard hardening trio for /tmp and removable media. remount changes options on a mounted filesystem in place: mount -o remount,ro /mount/point.

What an fstab line mounts, by how it names the device and whether a disk has been added. A grid of The name used against Since the line was written. /dev/sdb1: No disk added gives The filesystem you meant; A disk was added gives Whatever holds sdb1 now. UUID= or LABEL=: No disk added gives The filesystem you meant; A disk was added gives The filesystem you meant. Since the line was written → The name used ↓ No disk added A disk was added /dev/sdb1 The filesystem you meant Whatever holds sdb1 now UUID= or LABEL= The filesystem you meant The filesystem you meant
What an fstab line mounts, by how it names the device and whether a disk has been added.

Worth carrying in

mount -a
Mount everything in fstab not marked noauto. Run it before trusting a new entry.
umount /mnt
Detach. "Target is busy" means something has it open.
/etc/fstab
device, mount point, type, options, dump, fsck pass.
blkid
UUIDs and labels — the names that survive a disk being added.
lsblk -f
Block devices with filesystem type, label, UUID and mount point.
noauto / user / ro
Not at boot; mountable by a normal user; read-only.
mount -o remount,ro
Change options without unmounting.
findmnt
The mount table as a tree.
defaults
Shorthand for rw, suid, dev, exec, auto, nouser, async. Anything after it in the field overrides it.
srv-data.mount
A mount unit is named from its mount point, slashes turned to dashes. systemd-escape -p does it for you.

What the exam does with this

Objective
104. Devices, Linux filesystems, filesystem hierarchy standard
Share of the exam
25% (the whole objective)
Questions in this lesson
15
Signed for by a person
0

Partly checked. None of the 15 questions here has been read against the cited source by a person. 15 questions have been checked against their cited clause by an automated pass — which is not the same thing, and is not a signature.

Only questions a person has signed for are used in mock exams here. That is the whole difference between the two kinds of checking above.

How these questions are written — where each question comes from, what the verification ledger records, and what happens when one is found wrong.

Drill this lesson

A lesson is one sitting: the trainer draws a short run from these questions alone and spaces the ones you get wrong.

Practise Mounting and unmounting filesystems

Questions in this lesson

Practise Mounting and unmounting filesystems

The rest of objective 104