EMZETT.
Login

fstab and mount: Attaching drives to the file system

In short: On Linux storage devices are “attached” (mounted) to a folder; the file /etc/fstab defines what is mounted automatically at boot.

In more detail: Linux has no drive letters. There is a single directory tree starting at /. Further partitions, USB sticks or network drives are made visible at a mount point, i.e. an empty folder. Afterwards their files appear under this path.

In Depth

mount and umount

lsblk -f                      # show devices and file systems
sudo mount /dev/sdb1 /mnt/data
sudo mount -o ro /dev/sdb1 /mnt/data   # read-only
sudo umount /mnt/data         # unmount cleanly (not "unmount")

Always unmount before unplugging a device so that all writes are finished. If it is “busy”, lsof +f -- /mnt/data shows the open files.

The file /etc/fstab

Each line describes a file system for boot:

UUID=3f5c-... /          ext4   defaults,noatime  0 1
UUID=A1B2-... /boot/efi  vfat   umask=0077       0 2
UUID=9d7e-... /data      ext4   defaults          0 2
//nas/share /nas cifs credentials=/root/.smb,uid=1000 0 0

Columns: device (better UUID instead of /dev/sdb1, because names can change), mount point, file system, options, dump (usually 0), check order (fsck: 1 for root, 2 for others, 0 off).

Important options

noatime saves writes, ro/rw (read/write), noexec forbids starting programs, nosuid, nodev increase security (for example for /tmp), nofail prevents a missing drive from blocking boot, x-systemd.automount mounts only on access.

Pitfalls

An error in /etc/fstab can leave the system in emergency mode. After changes test with sudo mount -a before rebooting. blkid provides the UUID. Removable media on the desktop are usually mounted automatically by udisks under /run/media/user/. With findmnt you see all current mount points.

See also: File system hierarchy (FHS), Linux file systems, Partitions, LVM and LUKS