Rain WikiWindows · Linux · Android

/etc/fstab

Configuration fileAll Linux distributionsSafe to delete: No

/etc/fstab is the file that tells Linux which file systems to mount at boot, where, and with which options. Each line describes one file system or swap area. A wrong line can stop the system from booting normally, so changes should be tested before a reboot.

1The six fields

Each line has six fields: the device (for example UUID=...), the mount point, the file system type (ext4, xfs, vfat, swap), the mount options (for example defaults, noatime, nofail), the dump field (usually 0) and the fsck order (1 for the root file system, 2 for others, 0 to skip the check).

2Why UUIDs

Device names such as /dev/sdb1 can change when disks are added or reordered. A UUID or LABEL identifies the file system itself, so the right one is mounted. blkid or lsblk -f shows the UUIDs.

3nofail and systemd

With systemd, fstab lines are turned into mount units at boot. The 'nofail' option lets the boot continue if a non-essential disk, such as a USB drive, is missing.

How to add and test an fstab entry

  1. Find the UUID of the file system: lsblk -f
  2. Create the mount point, for example: sudo mkdir -p /mnt/data
  3. Back up the file: sudo cp /etc/fstab /etc/fstab.bak
  4. Add a line such as: UUID=<uuid> /mnt/data ext4 defaults,nofail 0 2
  5. Check the file: sudo findmnt --verify
  6. Mount everything listed without rebooting: sudo mount -a

Cautions

  • An error in the root or /boot line can make the system start in emergency mode.
  • Keep a copy of the working file and test with mount -a before rebooting.

Sources

  1. fstab(5) manual page man7.org
  2. findmnt(8) manual page man7.org

Last reviewed: