What is Fstab in Linux?
The /etc/fstab file contains information about file systems. It is used by several commands on Linux to define how file systems are mounted. Every filesystem that Linux supports supports many different mount options depending on the file system. For example, a filesystem called XFS, supports custom options like barriers/nobarriers, but ext4 supports options like discard if you are using solid state disks.
The /etc/fstab file is comprised for six fields or columns, device, mount point, file system type, mount options, dump options, fsck options.
|Device||Mount Point||File System||Mount Options||Dump Options||File System
Table 1 illustrates the fstab file in a table format. As you can see, you can as many entries in this file as you need. For complex layouts, you may have more or for simplier layouts, you may only have two or three entries, usually one for the / (root) filesystem, the proc file system and maybe swap, which is optional, but usually recommended.
The device represents the hardware that you want to access. The device, /dev/sda1 represents the first partion on the first disk of the system. Refering to the device is one way to reference a device. Another way, is to use the LABEL or UUID. Both LABEL and UUID both have distinct advantantes in that the UUID or LABEL should be unique to the device and never change. This means that if you re-order the drives, /dev/sda1 may become /dev/sdb1. As you can see, this would be problematic as they system boots up and can not find the / (root) volume. In newer distributions, you will most likely see devices referenced by their UUID.
In addition there are other special devices, such as proc and cgroup. The proc device is a special device that contains runtime information for your systems kernel. If you run “cat /proc/cpuinfo” you will see information related to your current CPU. The cgroup device is another special device used for Linux Containers (LXC) which is type of virtualization.
Mount point is the destination where you want the device to be accessible. For example, the / (root) mount point, will always be at the top level, /. However, you may have a seperate partition for /home, /var, or /usr, depending on your needs.
File System Type
As you work with Linux, you will notice that it supports many different types of operating systems. Some he examples include ext2, ext3, ext4, xfs, jfs, btrfs and the list goes on.
With such a large variety of file systems, they all have different options regarding how you mount them. This column provides a location for providing mount options. For example, if you are xfs, you may want to include barriers or nobarriers. Another options is “defaults” which just says use the default options.
This column specifies whether the filesystem should be backed up using the dump command. Most often this column is zero.
File System Check Options
The last column specifies the order that a filesystem check will be performed. A value of zero indicates that the filesystem will never be checked. The file systems, /proc, /cgroup, and /swap should never need to be checked, so a value of zero makes sense.