Linux: fstab file structure and options
The six columns of /etc/fstab, common mount options and the role of systemd.
/etc/fstab describes the file systems mounted at boot. Each line has six columns: device, mount point, file system type, options, dump flag and fsck order.
Entries mounted without an fstab line
On systemd-based distributions, /etc/fstab is no longer used in the traditional way. At boot, systemd reads each line of /etc/fstab and generates a mount unit for each entry. To see the status of every mount managed by systemd:
systemctl status *.mount
To list block devices with their file system, label, UUID and mount point:
sudo lsblk -o NAME,FSTYPE,LABEL,UUID,MOUNTPOINT
Column 1: device
UUID stands for Universal Unique Identifier. UUIDs can be listed as root with lsblk -f:
NAME FSTYPE LABEL UUID MOUNTPOINT
sda
|-sda1 ext4 rootfs 00000000-0000-0000-0000-000000000000 /
|-sda2 swap 00000000-0000-0000-0000-000000000000 [SWAP]
|-sda3 ext4 00000000-0000-0000-0000-000000000000 /var
`-sda4 ext4 00000000-0000-0000-0000-000000000000 /home
The partition can be referenced in several ways:
/dev/sda1 # by device name
UUID=00000000-0000-0000-0000-000000000000 # by UUID
LABEL=root # by label
Column 2: mount point
The directory in the global file system tree where the file system is attached (for example /). Any directory can be used.
Column 3: file system type
The file system type or the algorithm used to interpret it. In the example it is ext4. Common values: ext2, ext3, ext4, reiserfs, xfs, jfs, smbfs, btrfs, vfat, ntfs, swap.
Column 4: mount options
| Option | Meaning |
|---|---|
defaults |
Default options (equivalent to rw,suid,dev,exec,auto,nouser,async) |
auto |
Mounted automatically at boot or by mount -a |
noauto |
Mounted only on explicit request |
discard |
Enables TRIM on SSD |
nofail |
If the device is missing at boot, it is not mounted and does not block the boot |
rw / ro |
Mount read-write / read-only |
relatime |
Update the inode access time relative to the modification or change time |
noatime |
Do not update the inode access time |
user |
Allows any user to mount the file system (implies noexec,nosuid,nodev) |
nouser |
Only root may mount the file system (default) |
sync / async |
Synchronous / asynchronous I/O |
suid |
Allows suid and sgid bits (a binary can run with temporarily elevated privileges) |
nosuid |
Blocks suid and sgid bits |
exec |
Allows execution of binaries on this file system (default) |
noexec |
Forbids execution of binaries |
acl |
Enables ACL support |
Example line:
UUID=00000000-0000-0000-0000-000000000000 / ext4 noatime,acl 0 1
Column 5: dump
Used by the dump backup utility to decide whether the file system must be backed up. 0 means ignored, 1 means backed up. Most systems do not have dump installed, so 0 is the usual value.
Column 6: fsck order
Order in which fsck checks the file systems at boot. The root file system should have 1, other file systems to check should have 2, and 0 means no check.
Generating an fstab
genfstab -U /mnt >> /mnt/etc/fstab
# or
genfstab -U / >> /etc/fstab_gen
See also Mount a volume using systemd.
Examples
CIFS share with a credentials file
//fileserver01/share /mnt/share cifs user,uid=54321,gid=54321,rw,suid,_netdev,credentials=/etc/cifs_cred 0 0
Credentials file (/etc/cifs_cred):
username=app_user
password=<PASSWORD>
LVM volume
/dev/vgdata/lvdata /data ext4 defaults 1 2
Notes
- Restrict the permissions of the credentials file (for example
chmod 600, owned by root).