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.
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.
From left to right, fstab requires six total parameters, including the UUID. Below, we will go over some settings that might be useful for common configurations.
Describes the block special device or remote filesystem to be mounted
Describes the mount directory
Sets the file system type
Sets associated mount options
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.
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.
Fstab Entry Examples
The sections below contain example configurations for various fstab scenarios
Mounting Swap Space
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
# <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
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
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.
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.
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
Block Device Commands
When creating a new entry within fstab, sometimes you may need to find more information on the devices connected to your system. See the commands below for useful output. None of these commands, when ran verbatum, will make any changes to your system. They are only for gathering needed information.
Note that the output of the commands is present, but has been reduced (and obfuscated, where needed) to keep the length of this page down.
Print information on all connected block devices -
lsblk sda 8:0 0 931.5G 0 disk ├─sda1 8:1 0 128M 0 part ├─sda2 8:2 0 925.5G 0 part └─sda3 8:3 0 5.9G 0 part
Print the UUIDs of all connected block devices, along with some other hardware information -
sudo blkid /dev/sdb2: UUID="436b3ae3-4301-4b8a-80d3-fdf52c7d7059" TYPE="swap" PARTUUID="590670f6-3b89-41b5-b474-fcd6c048628d"
Print information on partitions one all connected block devices -
sudo parted -l Model: HDD A12345678-B3210 (scsi) Disk /dev/sdb: 2000GB Sector size (logical/physical): 512B/4096B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 1 1049kB 1000MB 999MB fat32 boot, esp 2 1000MB 17.0GB 16.0GB linux-swap(v1) 3 17.0GB 117GB 100GB ext4 4 117GB 217GB 100GB ext4 5 217GB 427GB 210GB ext4
Print information given a specific block device (partitions) -
sudo tune2fs -l /dev/sdb3 tune2fs 1.45.4 (23-Sep-2019) Filesystem volume name: <none> Last mounted on: / Filesystem UUID: fagbraetd325t9-6gafdee7-4d2344agdd-93d2-6f4safsafsa5d6 Filesystem magic number: 0xEF53 Filesystem revision #: 1 (dynamic) Filesystem features: has_journal ext_attr resize_inode dir_index filetype needs_recovery extent 64bit flex_bg sparse_super large_file huge_file dir_nlink extra_isize metadata_csum Filesystem flags: signed_directory_hash Default mount options: user_xattr acl Filesystem state: clean Errors behavior: Continue Filesystem OS type: Linux Filesystem created: Mon Oct 14 12:34:48 2019 Last mount time: Thu Oct 24 12:27:30 2019 Last write time: Thu Oct 24 12:27:30 2019 Mount count: 50 Maximum mount count: -1 Lifetime writes: 50 GB Default directory hash: half_md4 Directory Hash Seed: 4e7gds499c3-8532e0-452356c-432890c-d0fds43e2be81ee Journal backup: inode blocks Checksum type: crc32c Checksum: 0xb054235dk