The fstab file located in /etc/ contains descriptive information about the filesystems the system can mount. fstab is only read by programs, and not written; it is the duty of the system administrator to properly create and maintain this file. In almost all cases it will be created for you during the initial install but it can be useful to understand it in case you need to troubleshoot issues later or add extra items.
Here is an example of a typical fstab:
# # /etc/fstab # Created by anaconda on Fri Jan 5 21:12:58 2018 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # UUID=4d028ac1-d413-4d3a-94b4-251db287744f / ext4 defaults 1 1 UUID=c13ef520-fac6-49b5-8717-1afd49097ef4 /boot ext4 defaults 1 2 UUID=A588-0D36 /boot/efi vfat umask=0077,shortname=winnt 0 0 UUID=498ae307-b89e-47ac-b1fb-293c2342d417 swap swap defaults,pri=1 0 0 UUID=5010a5d7-9457-4a44-85c7-d836b39e06a2 swap swap defaults,pri=2 0 0
What we can see from the example above is:
- The Operating System was installed in UEFI mode which is why we have a separate mount point for /boot/efi – this just helps the system boot initially
- The /boot directory (that contains the kernels) is in a separate partition
- There is no separate directory or mount point for any other parts of the IS as everything else is simply in /
- There are 2 swap partitions and the last one is a lower priority than the 1st.
So what is this UUID and what partition or disk is that actually?
Modern Linux distributions use UUID’s in the fstab instead of the disk ID e.g. /dev/sda1, you can easily find out which UUID is which disk or device though by running ‘ls -lha /dev/disk/by-uuid/’
lrwxrwxrwx 1 root root 15 Jan 22 2021 4d028ac1-d413-4d3a-94b4-251db287744f -> ../../nvme0n1p4
As you can see from the UUID above it is actually on partition 4 on nvme0n1 (nvme0n1p4).
if you have multiple swap files you can also set the priority in which they are used, for example, if you have 2 disks and the OS is on 1 and the other is used for general storage, it might be advantageous to have the primary swap file on the second disk used first and only use the swap file or partition on the same disk as the OS if the first gets full. this is where the pri=1 or pri=3 etc come in handy. the higher the number the lower the priority so 2 will be used after 1 is full.
You can create a mount point yourself in the fstab to be automatically used on the system startup, for example, if you add a large disk for backups ad you want it to always mount at backup, assuming all you have done is added the disk and rebooted, no formatting or anything has happened you would do the following to achieve that (assuming /dev/sdb is the large disk and it is 500GB):
parted --script /dev/sdb \ mklabel gpt \ mkpart primary ext4 1MiB 500GiB mkfs.ext4 /dev/sdb1 mkdir /backups mount /dev/sdb1 /backups
Then if you want to add it to the fstab so it is always available after boot you need to first get the UUID as shown previously, lets assume it is: 5b2628eb-efb6-41f1-995d-ed9de3ff280a now add the following line to the fstab at the end:
UUID=5b2628eb-efb6-41f1-995d-ed9de3ff280a /backups ext4 defaults 0 0
Now disk/partition sdb1 will automatically mount on boot.