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.
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.
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,
fsckpass. - 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 -pdoes it for you.
What the exam does with this
- The sixth fstab field is the
fsckorder: 1 for root, 2 for others, 0 to skip. The fifth is dump and is nearly always 0. - UUID or LABEL rather than
/dev/sdX, because device names are assigned in detection order. - noauto means it is not mounted at boot but the entry still lets you mount it by name later.
- defaults is rw, suid, dev, exec, auto, nouser, async — asked verbatim, and the near-miss answers change one word of it.
- A mount unit's file name is derived from its mount point and nothing else:
/srv/dataissrv-data.mount, and no other spelling is accepted.
- 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
- In an /etc/fstab line, what does the sixth and last field control? machine-checked
- A server's /etc/fstab refers to data partitions as /dev/sdb1 and /dev/sdc1. After an extra disk controller is installed, the machine fails to boot correctly. Why does using UUID= instead avoid this class of failure? machine-checked
- Which /etc/fstab mount option keeps a filesystem from being mounted by `mount -a` during boot, while still allowing an administrator to mount it later by naming its mount point? machine-checked
- The root filesystem is mounted read-write and you need it read-only for a moment. You obviously cannot unmount it. Which command changes it in place? machine-checked
- You need the UUID of the filesystem on /dev/sda1 to write a persistent /etc/fstab entry. Select the TWO commands that will show it. machine-checked
- `umount /mnt/data` fails with 'target is busy'. Select the TWO commands that help you find out which processes are keeping it busy. machine-checked
- An /etc/fstab entry for an ext4 data partition carries the single word `defaults` in its fourth field. Which set of mount options does that keyword stand for? machine-checked
- A USB stick has an fstab entry with the mount point /media/usb. Any ordinary user should be allowed to mount it, but once mounted only the person who mounted it may unmount it again. Which mount option gives exactly that? machine-checked
- The directory /srv/data lives on its own filesystem and must also appear at /var/www/html/data, where a chrooted web server can reach it. A symbolic link is no use because it points outside the chroot. Which command makes the same directory tree visible at the second location? machine-checked
- An external disk carries a filesystem whose label is `backup`. Which command mounts it on /mnt/backup by that label, without naming any /dev node? machine-checked
- Rather than an /etc/fstab line, you want systemd to manage a mount at /srv/data with its own unit file. What must that unit file be called for systemd to accept it? machine-checked
- A mounted filesystem must be detached from the directory tree at once, even though processes still hold files open on it, with the real cleanup happening as soon as those references are gone. Which command does that? machine-checked
- A filesystem mounted at /srv/upload holds nothing but files uploaded by remote users. No program on it may ever be executed, any setuid bits on it must be ignored, and any device nodes found on it must be ignored. Select the THREE /etc/fstab options that enforce this. machine-checked
- You are surveying an unfamiliar server's storage. Type the command, with no options and no arguments, that lists all block devices as a tree showing each device's size, type and mount point. machine-checked
- The installation image /srv/iso/debian.iso must be inspected without burning it. The directory /mnt/iso already exists. Type the complete command that mounts the image there, requesting the loop device with a mount option. machine-checked
Practise Mounting and unmounting filesystems
The rest of objective 104
- Partitions and filesystems
- Keeping filesystems intact
- Mounting and unmounting filesystems — you are here
- File permissions, ownership and disk quotas
- Hard links and symbolic links
- Finding files and where they belong