Tom McKeesick

20220703 FSTAB

Note: This applies to Linux systems only!

What is /etc/fstab?

In order to mount a drive automatically in linux, you’ll have to ensure that it’s added to the /etc/fstab file.

Whenever I bootstrap a new linux server or desktop, this is one of the setup stages that I always do, to ensure that all of my drives are mounted correctly.

As I bootstrap automatically (mostly), I have quite a few configuration files for a heap of different apps & services that reference those drives, usually by the /mnt/<drive> path.
This means that I need to ensure that no matter which linux OS I’m using or reinstalling, that each drive will still be mounted to the same place

Help

See some more documentation by using man fstab in your terminal

The file format

I’ve modified the usual format and vertically-aligned all of the setting headings & values so that it’s easier to read (both for you and for me!). Usually, the options/dump/pass sections are all crammed together separated by a single space.

# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a device; this may
# be used with UUID= as a more robust way to name devices that works even if
# disks are added and removed. See fstab(5).
#
# <file system>                          <mount point>  <type>  <options>         <dump> <pass>
UUID=8e519e43-880b-4a9f-83b0-e83899493ca6 /              ext4    defaults,noatime 0      1
UUID=18A7-14C2                            /boot/efi      vfat    umask=0077       0      2

Some very basic explanations for some of the more mysterious fields

Making an entry

Let’s make an entry!

For our example, let’s imagine that we want to create an entry that mounts the music partition in the /mnt/music dir (which, hypothetically, we’ve already created).
(To make things more interesting, this partition is in ntfs format, aka a partition usually created in/for Windows)

  1. Find the partition information

    I use one command to get most of the information that I need to create the entry:

    sudo lsblk -o name,size,label,fstype,partlabel,uuid

     ☯ ~ sudo lsblk -o name,size,label,fstype,partlabel,uuid
     NAME          SIZE LABEL  FSTYPE   PARTLABEL    UUID
     nvme0n1     931.5G
     ├─nvme0n1p3 341.8G        ext4     root         0bbaa1ff-b625-4972-8099-b59dc15004ee
     ├─nvme0n1p4   334G        ext4     root         15cd5735-4977-430f-ab46-e1202e6ff854
     └─nvme0n1p5   7.8G swap   swap                  088a2190-6ed0-4f76-88ca-70803aada85f
     nvme1n1     931.5G
     ├─nvme1n1p1   512M        vfat                  1a5a2317-3a77
     └─nvme1n1p4 637.1G X      ntfs     music        d2320a36-68e6-4ea1-b5da-6374efa4b355
    
  2. Ensure that the mount directory exists

    You’ll have to ensure that the directory that the drive will be mounted at already exists! You can do this via the following commands:

     # Make the directory
     ☯ ~ sudo mkdir /mnt/music
     # Make your user the owner instead of root
     ☯ ~ sudo chown $USER:$USER /mnt/music
    
  3. Create the entry

     UUID=d2320a36-68e6-4ea1-b5da-6374efa4b355  /mnt/music  ntfs  errors=remount-ro  0  2
    
  4. Run!

You can restart your computer, or run

☯ ~ sudo mount -a

If there were no errors, you won’t see any output.

Then, check the contents of the mounted directory to see if it has been mounted as expected

☯ ~ ls -alh /mnt/music