Linux

fstab

Static filesystem table for mounting filesystems, swap, encrypted volumes, and network shares at boot.

#linux #fstab #mount #swap #nfs #storage

Getting Started

What /etc/fstab Does

/etc/fstab defines filesystems and swap areas that should be mounted automatically.

Each entry is processed at boot and can also be applied manually later.

Edit fstab

sudoedit /etc/fstab

Back Up Before Changes

sudo cp /etc/fstab /etc/fstab.bak.$(date +%F-%H%M%S)

Validate Syntax

findmnt --verify --verbose

Apply New Mount Entries

sudo mount -a

Apply Swap Entries

sudo swapon -a

Entry Format

Generic Layout

[source] [mount_point] [filesystem] [options] [dump] [pass]

Field Meanings

FieldMeaning
sourceDevice, UUID, LABEL, mapper path, or network export
mount_pointDirectory where the filesystem appears
filesystemFilesystem type such as ext4, xfs, vfat, swap, nfs, nfs4, tmpfs
optionsComma-separated mount options
dumpUsually 0; legacy backup flag
passFilesystem check order at boot

Common pass Values

ValueMeaning
0Do not run fsck
1Check first, usually root filesystem
2Check after root

Identify Filesystems Safely

UUIDs and labels are more stable than /dev/sdX names.

Show UUIDs

blkid

Show Filesystems and Mountpoints

lsblk -f

Show Current Mount Tree

findmnt

Common Local Filesystem Entries

ext4 Partition by UUID

Use this as the default pattern for most local data partitions.

UUID=[uuid] [mount_point] ext4 defaults 0 2

XFS Partition by UUID

Use 0 0 because XFS is not checked by fsck in the same way as ext filesystems.

UUID=[uuid] /srv/data xfs defaults 0 0

EFI System Partition

This is the common Linux EFI entry.

UUID=[uuid] /boot/efi vfat umask=0077 0 1

Read-Only Archive Mount

Useful for snapshots, archives, or forensic copies.

UUID=[uuid] /srv/archive ext4 ro,nodev,nosuid,noexec 0 2

On-Demand Backup Disk

Use noauto to prevent mounting at boot and nofail to avoid boot delays if the disk is absent.

UUID=[uuid] /mnt/backup ext4 noauto,nofail,x-systemd.automount 0 2

Swap Entries

Swap Partition by UUID

This is the standard swap partition entry.

UUID=[uuid] none swap sw 0 0

Swap File

Use this for systems configured with a swap file instead of a dedicated partition.

/swapfile none swap sw 0 0

High-Priority Swap Device

Higher pri values are used first.

UUID=[uuid] none swap defaults,pri=100 0 0

Encrypted Swap Mapper

This is common when the swap device is unlocked through /etc/crypttab.

/dev/mapper/cryptswap none swap defaults 0 0

Encrypted Partitions

For LUKS devices, define the unlock step in /etc/crypttab, then reference the mapper device in /etc/fstab.

crypttab Entry for a LUKS Volume

[mapper_name] UUID=[uuid] none luks

Mount Unlocked LUKS Volume

After unlock, the device appears under /dev/mapper/.

/dev/mapper/[mapper_name] /secure ext4 defaults 0 2

LUKS Volume with Hardened Mount Options

Useful for data partitions that should not allow device files or setuid binaries.

/dev/mapper/[mapper_name] /srv/secure xfs defaults,nodev,nosuid 0 0

Encrypted Logical Volume from LVM

This is common when LVM provides the logical volume and the mapper path is mounted directly.

/dev/mapper/vg0-data /data ext4 defaults 0 2

NFS and NFSv4 Mounts

Use _netdev for network filesystems so systemd waits for networking.

Use nofail when the system should still boot even if the server is unavailable.

Generic NFS Mount

This is a good baseline for a reliable NFS mount.

[server]:[export_path] /mnt/nfs nfs rw,hard,_netdev 0 0

NFS Mount with Explicit Version

Use this when the server supports NFSv4 but you prefer the nfs filesystem type.

[server]:[export_path] /srv/share nfs rw,vers=4.1,hard,_netdev 0 0

Native NFSv4 Mount

This is the direct nfs4 form.

[server]:[export_path] /mnt/nfs4 nfs4 rw,hard,timeo=600,retrans=2,_netdev 0 0

NFSv4 Automount

x-systemd.automount delays the actual mount until first access.

[server]:[export_path] /srv/projects nfs4 rw,hard,noatime,_netdev,x-systemd.automount,x-systemd.idle-timeout=600 0 0

Read-Only NFSv4 Share

Useful for published content, package mirrors, or report exports.

[server]:[export_path] /mnt/reports nfs4 ro,hard,_netdev,nofail 0 0

NFS Home Directories

This pattern is common in labs and shared Linux environments.

[server]:/home /home nfs4 rw,hard,intr,_netdev 0 0

Slow or Optional NFS Server

Reduce boot impact when the share is not critical.

[server]:[export_path] /mnt/optional nfs nofail,_netdev,x-systemd.device-timeout=10s 0 0

Advanced Examples

Bind Mount

Expose one directory tree at another path.

/var/log /srv/chroot/log none bind 0 0

tmpfs for /tmp

Keep temporary files in memory with a size cap.

tmpfs /tmp tmpfs defaults,noatime,mode=1777,size=2G 0 0

Removable Media Mounted by Regular User

Use this for local lab machines or workstations.

UUID=[uuid] /mnt/usb ext4 noauto,user,nofail 0 0

Read-Only ISO Mount

Useful for loop-mounted installation media or appliance images.

/srv/images/debian.iso /mnt/iso iso9660 loop,ro 0 0

Mount by Label

Labels can be easier to recognize than UUIDs in small environments.

LABEL=media /srv/media ext4 defaults 0 2

Useful Mount Options

OptionMeaning
defaultsDefault read-write mount behavior
roRead-only mount
rwRead-write mount
noautoDo not mount automatically with mount -a or at boot
nofailDo not fail boot if the mount is missing
userAllow a regular user to mount
usersAllow any user to mount and unmount
noexecDo not allow direct execution of binaries
nodevIgnore device files on the mounted filesystem
nosuidIgnore setuid and setgid bits
_netdevMark the filesystem as network-dependent
x-systemd.automountCreate an automount unit
x-systemd.idle-timeout=600Unmount after inactivity
x-systemd.device-timeout=10sLimit wait time for missing devices
vers=4.1Request a specific NFS protocol version
pri=100Set swap priority
bindBind an existing path to another mountpoint

Testing and Troubleshooting

Mount Everything from fstab

sudo mount -av

Mount One Entry by Mountpoint

sudo mount [mount_point]

Unmount One Entry

sudo umount [mount_point]

Check Active Swap Devices

swapon --show

Check Generated Mounts

findmnt --fstab

Inspect Boot-Time Mount Errors

journalctl -b -p warning

Regenerate systemd Mount Units After Changes

sudo systemctl daemon-reload

Best Practices

Use UUID= or LABEL= instead of raw /dev/sdX names whenever possible.

Use 0 2 for most local ext filesystems and 0 0 for network filesystems, swap, and XFS.

Use _netdev for NFS and other network-backed mounts.

Use nofail for removable disks, optional NAS shares, and anything that should not block boot.

Test with findmnt --verify --verbose and mount -a before rebooting.