Skip to content

Intermediate · Storage: partitions, file systems and LVM · topic 26 of 57 · 30 min

Permanent mounts with /etc/fstab and UUIDs

Explanation

/etc/fstab lists the file systems to mount at boot: one line each with the device, mount point, type, options, dump and fsck order. Use UUID= instead of /dev names because names can change. After editing, run systemctl daemon-reload and mount -a to catch mistakes BEFORE you reboot.

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.

output
# /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
Six fields, separated by spaces or tabs.
  1. Device: what to mount. Best as UUID=..., or LABEL=..., or an LVM path like /dev/mapper/vg-lv or /dev/vg/lv.
  2. Mount point: the directory (must exist). For swap write none (or swap).
  3. Type: xfs, ext4, swap, nfs and so on.
  4. Options: defaults, or a comma list such as defaults,noexec or ro. nofail lets the boot continue if this device is missing.
  5. Dump: 0 (old backup tool flag; leave 0).
  6. 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.

bash
# 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-3c6d2b8f9a10
Use the UUID, not the PARTUUID, in the first fstab field for a file system.

The safe workflow

bash
# 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% /data
If mount -a prints an error, fix the line NOW, while you are still logged in.
Careful: Use >> to add a line, never > (which replaces the whole fstab, including the root file system line). Better: open fstab in vim and add the line by hand. Keep a copy first: cp /etc/fstab /etc/fstab.bak.

When 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

/etc/fstab

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.

bash
[  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 maintenance

Practice (0/4 done)

Task 1 · Question

Which is the best device field for a data disk in fstab?

Task 2 · Question

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

Task 3 · Code · Python

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".

Task 4 · Practice

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

Question 1

1.Which command mounts everything listed in fstab that is not yet mounted?

Question 2

2.What should the 6th field be for an XFS file system?

Question 3

3.What does the nofail option do?

Question 4

4.The server boots into emergency mode because of fstab. What must you do before editing the file?

Question 5

5.Why run systemctl daemon-reload after editing fstab?

Read more (free)

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

Answer: xfs_growfs /data

xfs_growfs takes the mount point.

From Growing storage and adding swap

What does systemctl mask do?Related

Answer: Makes the unit impossible to start until unmasked

It links the unit to /dev/null.

From systemd services and systemctl

Which command shows file system types and UUIDs of block devices?Related

Answer: lsblk -f

lsblk -f (or blkid) shows FSTYPE and UUID.

From File systems and mounting: XFS, ext4, mount and df

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.

From Targets: the boot goal of the system

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

  1. 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.
  2. Module 5 exam: Storage · 14 questions · 25 min, without help. 5 topics of this module still to finish first.
  3. 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