Skip to content

Linux Foundations / Understand the system underneath ยท Step 7 of 38

Lesson: /etc/fstabSwitch
โ† Linux Foundations

System administration

/etc/fstab

Make mounts permanent with the filesystem table and test it before you reboot.

Mounts made by hand disappear at reboot. The file /etc/fstab lists the filesystems the system should know about and how to mount them.

The six fields

# device                                  mount point  type  options   dump pass
UUID=0a3b1c2d-1111-4222-8333-944455556666 /            ext4  defaults  0    1
UUID=5ef4138f-5574-4227-8c74-58be9b62c010 /srv/data    ext4  defaults  0    2

Fields are separated by spaces or tabs:

  1. What to mount: UUID=, LABEL=, a device path, or something like server:/share for NFS.
  2. Where: the mount point. Swap entries use none.
  3. Type: ext4, xfs, vfat, swap and so on.
  4. Options: comma separated.
  5. Dump: used by the old dump backup tool, normally 0.
  6. Pass: the order for filesystem checks at boot. Use 1 for the root filesystem, 2 for others, and 0 to skip.

Use UUIDs

Device names can change between boots. Get the UUID with:

$ sudo blkid /dev/sdb1
/dev/sdb1: UUID="5ef4138f-5574-4227-8c74-58be9b62c010" TYPE="ext4"

Useful options

  • defaults: the usual set, including read-write.
  • noauto: do not mount automatically at boot.
  • nofail: do not treat a missing device as a boot failure. Good for removable or optional disks.
  • ro, noexec, nosuid: restrict what is allowed.

Edit safely

A mistake here can leave a system stuck in emergency mode at boot. Back up first:

$ sudo cp /etc/fstab /etc/fstab.bak

Create the mount point, add your line, then check and apply:

$ sudo findmnt --verify
$ sudo mount -a
$ findmnt /srv/data

mount -a mounts everything in the file that is not already mounted, except entries marked noauto. If it prints an error, fix the line before rebooting. findmnt --verify is available in reasonably recent versions of util-linux.

On systems using systemd, run sudo systemctl daemon-reload after editing, because systemd generates mount units from this file.

Once an entry exists, you can mount it using just the mount point: sudo mount /srv/data.

Try it

Run cat /etc/fstab and identify all six fields on each line. Compare the UUIDs with the output of lsblk -f. Read man fstab, and only edit the file on a machine you can afford to repair.

Check your understanding

/etc/fstab

All 5 sections ยท no timer

Unlimited retries

Questions from every section are combined into one assessment. Answer them all correctly to complete the article.

Your completion saves in this browser. Sign in to sync it to your account.