/etc/fstab (filesystem table) lists the filesystems to mount at boot. Every permanent mount goes here: an extra data disk, swap, bind mounts and network shares. A mistake in this file is one of the most common reasons a Linux server doesn’t come back after a reboot, so it’s worth getting right.

The format

Each line has six fields separated by spaces or tabs:

# <device>                                 <mount point>  <type>  <options>          <dump> <pass>
UUID=0b4a8c1e-6c7e-4f34-9f6e-1a2b3c4d5e6f  /              ext4    errors=remount-ro  0      1
UUID=3f1c2d4e-aaaa-bbbb-cccc-123456789abc  /mnt/data      ext4    defaults,noatime,nofail  0  2
/swapfile                                  none           swap    sw                 0      0
  1. Device — what to mount. Prefer UUID= or LABEL= to /dev/vdb1.
  2. Mount point — an existing directory (none for swap).
  3. Type — ext4, xfs, btrfs, swap, nfs, cifs, tmpfs, none (for bind)…
  4. Options — comma-separated, no spaces.
  5. Dump — legacy backup flag. Use 0.
  6. Pass — fsck order at boot: 1 for the root filesystem, 2 for others, 0 to skip (XFS, Btrfs, network, swap).

Why UUIDs

Device names depend on detection order. Add a disk, and /dev/vdb may become /dev/vdc. Then the wrong disk gets mounted, or the boot fails. UUIDs stay with the filesystem:

sudo blkid
lsblk -f

See lsblk and blkid.

Add a data disk: a safe workflow

# 1. find the filesystem UUID
sudo blkid /dev/vdb1

# 2. create the mount point
sudo mkdir -p /mnt/data

# 3. back up fstab, then add the line
sudo cp /etc/fstab /etc/fstab.bak
echo 'UUID=3f1c2d4e-aaaa-bbbb-cccc-123456789abc /mnt/data ext4 defaults,noatime,nofail 0 2' | sudo tee -a /etc/fstab

# 4. reload systemd and test
sudo systemctl daemon-reload
sudo mount -a
findmnt /mnt/data

sudo findmnt --verify checks fstab for errors (unknown UUIDs, missing directories, bad options). Run it before rebooting. If mount -a reports an error, fix it before rebooting.

Formatting and partitioning come first. See fdisk and mkfs.

Common options

Option Meaning
defaults rw, suid, dev, exec, auto, nouser, async
noatime Don’t write access times. Fewer writes, slightly faster
nofail Don’t fail the boot if the device is missing
x-systemd.device-timeout=10s How long to wait for the device
_netdev Network filesystem: wait for the network
ro Read-only
noexec,nosuid,nodev Hardening for data or upload partitions
errors=remount-ro (ext4) Go read-only on filesystem errors
x-systemd.automount Mount on first access instead of at boot
discard Continuous TRIM (usually a periodic fstrim.timer is preferred)

Always use nofail for non-essential disks. Without it, a missing or broken data disk drops the server into emergency mode at boot.

Swap

/swapfile  none  swap  sw  0  0

See swap file vs partition.

Bind mounts

/srv/data/www  /var/www  none  bind  0  0

Make sure the source is mounted first. systemd usually orders this correctly. Add x-systemd.requires-mounts-for=/srv/data if needed.

Network shares

# NFS
10.0.0.5:/exports/backups  /mnt/backups  nfs   defaults,_netdev,nofail  0  0

# SMB/CIFS
//nas.local/backup  /mnt/nas  cifs  credentials=/root/.smbcred,uid=1000,gid=1000,_netdev,nofail  0  0

Add x-systemd.automount for network mounts so boot never waits on an unreachable server.

tmpfs

tmpfs  /tmp  tmpfs  defaults,size=1G,noexec,nosuid,nodev  0  0

It lives in RAM and is cleared on reboot.

Special characters in paths

Spaces in mount points must be written as \040: /mnt/my\040disk. It’s easier to avoid spaces.

When fstab breaks the boot

Symptoms: the server doesn’t come back after a reboot, and the console shows “You are in emergency mode” or “A start job is running for dev-disk-by…”.

  1. Open your provider’s VNC console. VPS.DO plans include one in the control panel.
  2. In emergency mode, enter the root password. If the root filesystem is read-only, remount it: mount -o remount,rw /.
  3. Fix or comment out the bad line in /etc/fstab, or restore /etc/fstab.bak.
  4. Run systemctl daemon-reload && mount -a, then reboot.

Without a root password, interrupt the boot at the GRUB menu in the console, add init=/bin/bash (or rd.break on RHEL) to the kernel line, remount / read-write and edit /etc/fstab. See mount.

Applying changes without a reboot

sudo systemctl daemon-reload    # systemd regenerates mount units from fstab
sudo mount -a                   # mount everything not yet mounted
sudo mount -o remount /mnt/data # apply changed options to a mounted fs

Quick reference

Task Command
Get UUIDs sudo blkid / lsblk -f
Check fstab sudo findmnt --verify
Test entries sudo mount -a
Reload after edit sudo systemctl daemon-reload
Safe data disk line UUID=… /mnt/data ext4 defaults,noatime,nofail 0 2

Related: resize a disk partition and LVM guide.

  • Linux
  • Storage
  • Configuration