Linux Command Reference ยท Disks and Filesystems
The /etc/fstab file and mount options
Reference for /etc/fstab: the six fields, UUID entries, common mount options such as noexec, nofail and noatime, the dump and fsck columns, and testing safely.
/etc/fstab ("file system table") is a plain text file that tells Linux which filesystems to mount, where, and with which options. The boot process (or systemd, which turns every line into a mount unit) reads it, and so does mount -a. A line in it also lets you type mount /data without repeating the device and options.
A mistake in this file can stop a machine from booting normally, so it pays to know exactly what every field means and how to check your edits before rebooting.
# <device> <mount point> <type> <options> <dump> <pass> UUID=3f1c2b9e-5a41-4d5e-9a77-0c8a1d6e2f10 /data ext4 defaults,noatime 0 2
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Syntax
Each non-comment line has six whitespace-separated fields:
| # | Field | Meaning |
|---|---|---|
| 1 | device | What to mount: UUID=..., LABEL=..., PARTUUID=..., a path such as /dev/sdb1 or /dev/mapper/vg0-data, a network share (server:/export), or a pseudo name such as tmpfs. |
| 2 | mount point | Directory to mount on (must exist). none for swap. Escape spaces as \040. |
| 3 | type | Filesystem type: ext4, xfs, btrfs, vfat, nfs, tmpfs, swap, or auto to detect it. |
| 4 | options | Comma separated mount options (below). defaults means the usual set. |
| 5 | dump | 0 or 1: whether the old dump backup tool should save it. Almost always 0. |
| 6 | pass | Order of fsck at boot: 1 for the root filesystem, 2 for others, 0 to skip. |
Frequently used options:
| Option | Effect |
|---|---|
defaults |
Shorthand for rw,suid,dev,exec,auto,nouser,async. |
ro / rw |
Read-only or read-write. |
noexec |
Forbid running programs from this filesystem. |
nosuid |
Ignore set-user-ID and set-group-ID bits. |
nodev |
Do not interpret device files. |
noatime |
Do not update the access time on reads; fewer writes. (relatime is the usual default.) |
nofail |
Boot continues even if the device is missing. |
noauto |
Do not mount at boot or with mount -a; mount only by name. |
user / users |
Allow ordinary users to mount. |
x-systemd.automount |
Mount on first access; x-systemd.device-timeout=5s limits waiting. |
errors=remount-ro |
ext4: on errors remount read-only. |
size=512m |
tmpfs: limit its size. |
uid=1000,gid=1000,umask=022 |
For vfat/exfat/ntfs: assign ownership, since they have no Unix owners. |
_netdev |
Network filesystem: wait until the network is up. |
Usage notes
- Use UUIDs for local disks. Names like
/dev/sdb1can change between boots. Find the UUID withblkidorlsblk -f. - Test before you reboot. Run
sudo mount -a: it mounts everything not yet mounted and reports errors. Also runfindmnt --verify. A bad line found now costs a minute; found at boot, a rescue shell. nofailfor non-essential disks. Without it, systemd waits for the device and drops into emergency mode when it is absent. Combine withx-systemd.device-timeout=for removable media.- After editing, reload systemd:
sudo systemctl daemon-reload, because systemd generates mount units from fstab. - Hardening idea: mount
/tmp,/var/tmpand/dev/shmwithnosuid,nodev,noexecwhere your software allows;noexecis bypassed by running an interpreter on a script file, so it is not a complete defense. - Bind mounts:
/srv/www /var/www none bind 0 0makes a directory show up twice. - Do not set pass on filesystems that need no fsck (
xfs,btrfs,tmpfs,vfaton many setups); use0. - Options come from two places: mount options in fstab, and per-filesystem defaults stored in the filesystem itself (set with
tune2fs -o). The kernel merges them. - Comments and blank lines are allowed; tabs and spaces are equivalent.