Mounting Default Filesystems

Surely at some point you will come across the need to mount an additional partition, either temporarily or with persistance across reboots. To do this, you will need to modify the settings within the /etc/fstab configuration file. See the details below for more information.

ArchWiki - Fstab

Fstab Parameters

At first glance, knowing misconfiguration can cause system failure, editing this file can be intimidating. To ensure no mistakes are made, understand what you are specifying when creating a new Fstab entry. Its important to always backup your settings before modifying this file, as in the event of system failure you can always simply restore your misconfiguration with this last working Fstab entry.

Device

Describes the block special device or remote filesystem to be mounted

Dir

Describes the mount directory

Type

Sets the file system type

The auto type lets the mount command guess what type of file system is used. This is useful for optical media (CD/DVD/Blu-ray).

ArchWiki - Fstab Usage

Options

Sets associated mount options

Dump

dump(8)

Option to check the filesystem with the dump(8) utility. This field is usually set to 0, which disables the check.

The fifth field, (fs_freq), is used for these filesystems by the dump(8) command to determine which filesystems need to be dumped. If the fifth field is not present, a value of zero is returned and dump will assume that the filesystem does not need to be dumped.

man 5 fstab

Fsck

fsck(8) Sets the order for filesystem checks at boot time

For the root device it should be 1. For other partitions it should be 2, or 0 to disable checking.

The sixth field, (fs_passno), is used by the fsck(8) program to determine the order in which filesystem checks are done at reboot time. The root filesystem should be specified with a fs_passno of 1, and other filesystems should have a fs_passno of 2. Filesystems within a drive will be checked sequentially, but filesystems on different drives will be checked at the same time to utilize parallelism available in the hardware. If the sixth field is not present or zero, a value of zero is returned and fsck will assume that the filesystem does not need to be checked.

man 5 fstab

If the root file system is of the btrfs type, the fsck order should be set to 0 instead of 1. See fsck.btrfs(8).

ArchWiki - Fstab Usage

Fstab Swap Entry

For example, to add a swap partition entry created by following the Swap Allocation instructions, an entry similar to the below would be added to our /etc/fstab

# <device> <dir> <type> <options> <dump> <fsck>
LABEL=SYSTEM   /        ext4   defaults        0 0
LABEL=UEFI      /boot/efi       vfat    defaults        0 0
/swapfile none swap defaults 0 0

Note that the first line is a comment I tossed into my /etc/fstab and is not there by default. The SYSTEM and UEFI lines are default mount configurations for our root filesystem and boot partitions, respectively. If you have defined a dedeicated parition for your /home directory, it would also be listed here, sometimes labeled as DATA.

Our swap partition is defined by the final line -

/swapfile none swap defaults 0 0

/swapfile points to the swapfile we created following the Swap Allocation instructions.

none tells our system not to mount this device anywhere within our filesystem for access / reading by the user.

swap defines the partition as the swap filesystem type

defaults passes the default set of options for this fstab entry

dump is set to 0, which disbales dump(8) from running its filesystem check

fsck is set to 0, which disables the fsck(8) integrity check, since this is swap space and not an actualy filesystem.

Optional Mounts

Sometimes, a filesystem may be removed from a system temporarily. We still use fstab to mount this filesystem, but we need to prepare the system for the case that it is not present for mounting at system boot.

External devices that are to be mounted when present but ignored if absent may require the nofail option. This prevents errors being reported at boot. For example:

/dev/sdg1        /media/backup    jfs    nofail,x-systemd.device-timeout=1ms    0  2

The nofail option is best combined with the x-systemd.device-timeout option. This is because the default device timeout is 90 seconds, so a disconnected external device with only nofail will make your boot take 90 seconds longer, unless you reconfigure the timeout as shown. Make sure not to set the timeout to 0, as this translates to infinite timeout.

ArchWiki - External Devices

Network Shares

If your external device requires another systemd unit to be loaded (for example the network for a network share) you can use x-systemd.requires=x combined with x-systemd.automount to postpone automounting until after the unit is available. For example:

//host/share    /net/share        cifs   noauto,nofail,x-systemd.automount,x-systemd.requires=network-online.target,x-systemd.device-timeout=10,workgroup=workgroup,credentials=/foo/credentials    0 0

ArchWiki - External Devices