/etc/fstab
/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
- Find the UUID of the file system:
lsblk -f - Create the mount point, for example:
sudo mkdir -p /mnt/data - Back up the file:
sudo cp /etc/fstab /etc/fstab.bak - Add a line such as: UUID=<uuid>
/mnt/dataext4 defaults,nofail 0 2 - Check the file:
sudo findmnt --verify - Mount everything listed without rebooting:
sudo mount -a
Cautions
- An error in the root or
/bootline can make the system start in emergency mode. - Keep a copy of the working file and test with mount -a before rebooting.
Related articles
- lsblk and block devicesHow to list disks and partitions with lsblk, read sizes, file systems and mount points, and identify a new disk safely.
- Swap space on LinuxWhat swap is, how to see it with free and swapon, how to add a swap file, and what vm.swappiness changes.
- df (disk free)How to read df output, why Use% can reach 100% before Avail is zero for normal users, and how to check inodes with df -i.
Sources
- fstab(5) manual page man7.org
- findmnt(8) manual page man7.org
Last reviewed: