Intermediate · Storage: partitions, file systems and LVM · topic 26 of 57 · 30 min
Permanent mounts with /etc/fstab and UUIDs
Explanation
Why fstab matters
At boot, systemd reads /etc/fstab and mounts each line. It is one of the most important files on the server: a mistake in it can stop the system from booting to normal mode. So learn the format exactly, and always test before rebooting.
# /etc/fstab
# device mount point type options dump fsck
/dev/mapper/rhel-root / xfs defaults 0 0
UUID=8f1c0d2a-6b3e-4d7f-9a1b-2c3d4e5f6a7b /boot xfs defaults 0 0
/dev/mapper/rhel-swap none swap defaults 0 0
UUID=5b2f3c1e-8d7a-4f0b-a9e1-3c6d2b8f9a10 /data xfs defaults 0 0
UUID=0e9c7d6b-1a2f-4c3d-8e5f-6a7b8c9d0e1f /backups ext4 defaults,nofail 0 2- Device: what to mount. Best as UUID=..., or LABEL=..., or an LVM path like /dev/mapper/vg-lv or /dev/vg/lv.
- Mount point: the directory (must exist). For swap write none (or swap).
- Type: xfs, ext4, swap, nfs and so on.
- Options: defaults, or a comma list such as defaults,noexec or ro. nofail lets the boot continue if this device is missing.
- Dump: 0 (old backup tool flag; leave 0).
- fsck order: 0 = never check at boot (always for XFS, which checks itself), 1 = the root file system for ext4, 2 = other ext4 file systems.
Why UUIDs and not /dev/sdb1?
Disk names like /dev/sdb are given in the order the kernel finds disks at boot. Add a new disk or a USB stick, or change a controller, and yesterday's sdb may be today's sdc. Your fstab would then mount the wrong disk, or fail. A UUID belongs to the file system itself and never changes. LVM paths (/dev/vgdata/lvdata) are also stable, because LVM finds its volumes by their own IDs.
# blkid /dev/vdb1
/dev/vdb1: UUID="5b2f3c1e-8d7a-4f0b-a9e1-3c6d2b8f9a10" TYPE="xfs" PARTLABEL="data" PARTUUID="a1b2c3d4-..."
# lsblk -no UUID /dev/vdb1
5b2f3c1e-8d7a-4f0b-a9e1-3c6d2b8f9a10The safe workflow
# mkdir -p /data
# echo "UUID=5b2f3c1e-8d7a-4f0b-a9e1-3c6d2b8f9a10 /data xfs defaults 0 0" >> /etc/fstab
# systemctl daemon-reload # let systemd re-read fstab
# mount -a # mount everything in fstab that is not mounted yet
# findmnt --verify # check fstab for errors
Success, no errors or warnings detected
# df -h /data
Filesystem Size Used Avail Use% Mounted on
/dev/vdb1 2.0G 47M 2.0G 3% /dataWhen it goes wrong anyway
If a bad fstab line points at a missing disk, the boot waits about 90 seconds and then drops to emergency mode, asking for the root password. Log in, run mount -o remount,rw / so you can edit, fix or comment out the line with vi, then systemctl daemon-reload and reboot. Adding nofail to non-critical lines (like a USB backup disk) avoids this situation.
Common mistakes
- Typos in the UUID. Copy it with blkid output or use a command like lsblk -no UUID /dev/vdb1 >> /etc/fstab and then fix the line in vim.
- A mount point directory that does not exist.
- Wrong type: writing ext4 for an XFS file system. mount -a will complain.
- Rebooting without running mount -a first. Always test.
Need help?
Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.
Try:
Watch the lesson
Permanent mounts with /etc/fstab and UUIDs · 1/7
slash etc slash fstab lists the file systems mounted at every boot.
Prefer a video by a teacher? Find free videos on “etc fstab uuid blkid mount -a tutorial rhel” on YouTube ↗
In real life: The reboot that took a news website down
A news portal in Kolkata added a second disk and put "/dev/sdb1 /media xfs defaults 0 0" in fstab. Months later a new disk was added; after a kernel update reboot, the old disk became /dev/sdc and the server stopped in emergency mode at 6 am, before the morning rush. The fix was to boot, remount root read-write, change the line to UUID=..., and add nofail. Their checklist now says: UUIDs only, and mount -a before any reboot.
[ OK ] Reached target Local File Systems (Pre).
[ TIME ] Timed out waiting for device /dev/sdb1.
[DEPEND] Dependency failed for /media.
You are in emergency mode. After logging in, type "journalctl -xb" to view system logs...
Give root password for maintenancePractice (0/4 done)
Which is the best device field for a data disk in fstab?
Which line has the bug? 1: UUID=0e9c... /backups ext4 defaults 0 2 2: UUID=5b2f... /data xfs defaults 0 3: /dev/vg01/lv01 /srv xfs defaults 0 0
Write check_fstab_line(line) that returns a list of problems (empty list = OK) for one fstab line. Ignore blank lines and comments (return []). Problems to report, as these exact strings: "fields" if there are not exactly 6 fields; then (only when there are 6) "device" if the device does not start with "UUID=", "LABEL=" or "/dev/"; "mountpoint" if the mount point does not start with "/" and is not "none" or "swap"; "fsck" if the type is xfs and the last field is not "0".
Make the XFS partition from the last lesson mount at /mnt/xfsdata at every boot using its UUID. Test without rebooting, then reboot to prove it.
Quick quiz
Read more (free)
Related help
Before this, learn
This topic builds on these. If something here feels new, open them first.
Related topics
- LVM: physical volumes, volume groups and logical volumesStorage: partitions, file systems and LVM · same module
- Disks and partitions: MBR, GPT, fdisk and partedStorage: partitions, file systems and LVM · same module
- GRUB2, kernel arguments and the default kernelBoot, recovery and containers
- Persistent storage and containers as systemd servicesBoot, recovery and containers
- firewalld: zones, services and portsSoftware and networking
- Data types, naming and good habitsSQL and Databases · Schema design and normalisation
Questions people ask about this
Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.
Which command mounts everything listed in fstab that is not yet mounted?
Answer: mount -a
mount -a reads fstab and mounts what is missing.
What should the 6th field be for an XFS file system?
Answer: 0
XFS is not checked by fsck at boot, so 0.
What does the nofail option do?
Answer: Lets the boot continue if the device is missing
Without it, a missing device can drop the boot into emergency mode.
The server boots into emergency mode because of fstab. What must you do before editing the file?
Answer: mount -o remount,rw /
Root is read-only in emergency mode.
Why run systemctl daemon-reload after editing fstab?
Answer: systemd generates mount units from fstab and must re-read it
systemd turns fstab lines into .mount units.
Which command grows a mounted XFS file system to fill its LV?Related
What does systemctl mask do?Related
Answer: Makes the unit impossible to start until unmasked
It links the unit to /dev/null.
Which command shows file system types and UUIDs of block devices?Related
Answer: lsblk -f
lsblk -f (or blkid) shows FSTYPE and UUID.
In emergency mode, how is the root file system mounted?Related
Answer: Read-only
Root is read-only; use mount -o remount,rw / to change files.
Pass the quiz (60% or more) or mark this topic as done when you are ready.
Your progress is saved on this device only.
Next steps
- 2 more topics in “Storage: partitions, file systems and LVM” before its exam: LVM: physical volumes, volume groups and logical volumes, Growing storage and adding swap.
- Module 5 exam: Storage · 14 questions · 25 min, without help. 5 topics of this module still to finish first.
- Then the next module, SELinux and SSH. 57 topics left in the course before the final exam.
← Previous: File systems and mounting: XFS, ext4, mount and df