/etc/fstab Basics

Linux Logo

/etc/fstab Basics.
This file sets out what disks will be automatically mounted at boot time.
Local, USB, SATA, NVME, Remote Network, SMB etc. Can all be configured to mount in this file.

Where to Mount a Disk?

Anywhere you like Linux will not stop you.
However by convention disks are normally mounted in wither of two locations

  • /mnt For permanent disks. Such as internal NVME or SATA HDD. Expected to always be available.
  • /media For temporary and removable disks. Such as USB Thumb drives or External USB drives.

Column Definitions

  1. File System:
    It is recommended to enter it as a UUID.
    /dev/sda etc is acceptable too.
  2. Mount Point:
    What folder you will be accessing the mounted volume from
    E.g. /mnt/backup. Ensure this directory exists before mounting.
  3. Type:
    ext4,vfat,sw
  4. Options:
    1. defaults:
      1. rw,suid
      2. dev
      3. exec
      4. auto
      5. nouser
      6. async
    2. noatime,errors=remount-ro
    3. noauto (Do not auto mount)
  5. Dump:
    0. Rarely used today.
  6. Pass:
    1. Order of filesystem integrity checking. If something goes wrong at boot the order in which disk checks will be done. Root filesystems should always be checked first.

Check if Disk is mounted

List all disk mounts

mount
/dev/mmcblk0p2 on / type ext4 (rw,noatime)
devtmpfs on /dev type devtmpfs (rw,relatime,size=439916k,nr_inodes=109979,mode=755)
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
proc on /proc type proc (rw,relatime)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,nodev,mode=755)
tmpfs on /run/lock type tmpfs (rw,nosuid,nodev,noexec,relatime,size=5120k)
tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,mode=755)
cgroup2 on /sys/fs/cgroup/unified type cgroup2 (rw,nosuid,nodev,noexec,relatime,nsdelegate)
cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,name=systemd)
none on /sys/fs/bpf type bpf (rw,nosuid,nodev,noexec,relatime,mode=700)
cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (rw,nosuid,nodev,noexec,relatime,net_cls,net_prio)
cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpu,cpuacct)
cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)
cgroup on /sys/fs/cgroup/pids type cgroup (rw,nosuid,nodev,noexec,relatime,pids)
cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
systemd-1 on /mnt/surveillance/1 type autofs (rw,relatime,fd=29,pgrp=1,timeout=0,minproto=5,maxproto=5,direct)
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=34,pgrp=1,timeout=0,minproto=5,maxproto=5,direct)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
mqueue on /dev/mqueue type mqueue (rw,relatime)
systemd-1 on /mnt/surveillance/0 type autofs (rw,relatime,fd=42,pgrp=1,timeout=0,minproto=5,maxproto=5,direct)
sunrpc on /run/rpc_pipefs type rpc_pipefs (rw,relatime)
configfs on /sys/kernel/config type configfs (rw,relatime)
/dev/mmcblk0p1 on /boot type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,errors=remount-ro)
tmpfs on /run/user/1000 type tmpfs (rw,nosuid,nodev,relatime,size=94636k,mode=700,uid=1000,gid=1000)
fusectl on /sys/fs/fuse/connections type fusectl (rw,relatime)
gvfsd-fuse on /run/user/1000/gvfs type fuse.gvfsd-fuse (rw,nosuid,nodev,relatime,user_id=1000,group_id=1000)

List only a specific disk

mount | grep -i 'mmcblk0p1'
/dev/mmcblk0p1 on /boot type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,errors=remount-ro)

Find UUID of Available Disks

sudo dlkid
/dev/mmcblk0p1: LABEL_FATBOOT="boot" LABEL="boot" UUID="5DE7-66CC" TYPE="vfat" PARTUUID="99999999-01"
/dev/mmcblk0p2: LABEL="rootfs" UUID="ffffffff-bbbb-7777-9999-00000000000f" TYPE="ext4" PARTUUID="99999999-02"
/dev/mmcblk0: PTUUID="99999999" PTTYPE="dos"

List Mounted Disks and Free Space

sudo df -h
Filesystem                            Size  Used Avail Use% Mounted on
/dev/root                              15G  2.2G   12G  16% /
devtmpfs                              430M     0  430M   0% /dev
tmpfs                                 463M   16K  463M   1% /dev/shm
tmpfs                                 463M  6.3M  456M   2% /run
tmpfs                                 5.0M  4.0K  5.0M   1% /run/lock
tmpfs                                 463M     0  463M   0% /sys/fs/cgroup
/dev/mmcblk0p1                        253M   48M  205M  19% /boot
tmpfs                                  93M     0   93M   0% /run/user/1000

Sample /etc/fstab files

Raspberry Pi OS

proc                   /proc          proc    defaults          0       0
PARTUUID=ffffffff-01  /boot           vfat    defaults          0       2
PARTUUID=ffffffff-02  /               ext4    defaults,noatime  0       1

Mounting Disks

sudo mount /mnt/xxx

Will mount the individual mount-point if it exists in /etc/fstab

sudo mount -a

Attempts to mount add disks configured in /etc/fstab/

Un Mounting Disks

sudo umount /mnt/xxx

Sample Configuration Examples

Mount Anonymous Guest File Share

//10.10.10.10/remote_file_share /mnt/file_share cifs _netdev,guest,comment=systemd.automount 0 0

Related

Links

  • https://en.wikipedia.org/wiki/Fstab