Under Linux, all partitions used by the system must be listed in /etc/fstab. This file contains the mount points of those partitions (where they are seen in the file system structure), how they should be mounted and with what special options (automatically or not, whether users can mount them or not, etc.)
The fstab file
The /etc/fstab file uses a table-like syntax. Every line consists of six fields, separated by whitespace (space(s), tabs or a mixture). Each field has its own meaning:
- The first field shows the block special device or remote filesystem to be mounted. Several kinds of device identifiers are available for block special device nodes, including paths to device files, filesystem labels and UUIDs, and partition labels and UUIDs.
- The second field shows the mount point at which the partition should be mounted.
- The third field shows the filesystem used by the partition.
- The fourth field shows the mount options used by mount when it wants to mount the partition. As every filesystem has its own mount options, users are encouraged to read the mount man page (man mount) for a full listing. Multiple mount options are comma-separated.
- The fifth field is used by dump to determine if the partition needs to be dumped or not. This can generally be left as 0 (zero).
- The sixth field is used by fsck to determine the order in which filesystems should be checked if the system wasn't shut down properly. Btrfs filesystems should have 0 here. On other filesystems the root filesystem should have 1 while the rest should have 2 (or 0 if a filesystem check isn't necessary).
The default /etc/fstab file provided by Gentoo is not a valid fstab file but instead more of a template.
In the remainder of the text, the partitions (and the respective /dev/mmcblk* block device files) outlined in the default partitioning scheme will be used. Correspondingly, the subvolumes used from this point on will be kept in line with the default Btrfs filesystem layout.
Filesystem labels and UUIDs
Both MBR (BIOS) and GPT include support for filesystem labels and filesystem UUIDs. These attributes can be defined in /etc/fstab as alternatives for the mount command to use when attempting to find and mount block devices. Filesystem labels and UUIDs are identified by the LABEL and UUID prefix and can be viewed with the blkid command:
If the filesystem inside a partition is wiped, then the filesystem label and the UUID values will be subsequently altered or removed.
Because of uniqueness, readers that are using an MBR-style partition table are recommended to use UUIDs over labels to define mountable volumes in /etc/fstab.
Partition labels and UUIDs
Users who have gone the GPT route have a couple more 'robust' options available to define partitions in /etc/fstab. Partition labels and partition UUIDs can be used to identify the block device's individual partition(s), regardless of what filesystem has been chosen for the partition itself. Partition labels and UUIDs are identified by the PARTLABEL and PARTUUID prefixes respectively and can be viewed nicely in the terminal by running the blkid command:
While not always true for partition labels, using a UUID to identify a partition in fstab provides a guarantee that the bootloader will not be confused when looking for a certain volume, even if the filesystem would be changed in the future. Using the block device files (/dev/mmcblk*) for defining the partitions in fstab is risky for systems that are restarted often and have storage media (and thus block devices) added and removed regularly.
The naming for block device files depends on a number of factors, including how and in what order the storage devices are attached to the system. They also could show up in a different order depending on which of the devices are detected by the kernel first during the early boot process. With this being stated, unless one intends to constantly fiddle with the device ordering, using default block device files is a simple and straightforward approach.
Creating the fstab file
Create the fstab file that once the installation is finished and the target system runs will be located at /etc/fstab:
nano -w /mnt/gentoo/etc/fstab
To successfully mount Btrfs subvolumes additionally the
subvol= mount option needs to be set and given the name of the respective subvolume that is to be mounted. Otherwise the system wouldn't take the Btrfs filesystem's structure into account and instead mount the parent volume, which in turn would render all files relevant to boot the target system inaccessible under their expected paths.
Add the rules that match the previously decided partitioning scheme and, if applicable, Btrfs filesystem structure. If other partitions or drives are used, append rules for those devices too.
If firmware=rockchip Configuring the system - Example fstab for Rockchip devices
If firmware=uefi Configuring the system - Example fstab for UEFI devices
If firmware=raspi4 Configuring the system - Example fstab for Raspberry Pi4
If firmware=depthcharge Configuring the system - Example fstab for depthcharge devices