How to permanently mount partitions on Linux

H

The fstab file (located in the /etc directory) controls how Linux provides access to the partitions on the hard disk. Linux has a unified directory structure, where each partition is mounted (mapped) to a specific point in the file tree.

Many Linux folders are located on partitions other than the root partition (/); for example, if the /etc directory is on the same partition with partition /, the /home directory can be located on another partition. The /etc/fstab file describes how these file systems are arranged in the Linux distribution structure (the name fstab is an abbreviation for filesystem tables).

The /etc/fstab file consists of a series of lines each containing 6 fields. These fields are separated by one or more spaces or tabs. A line starting with # is completely ignored.

Explanation of each field in fstab

File system – The first column specifies the partition to be mounted. It represents the file name of the partition’s hard disk ( /dev/sda1 or /dev/sdb3) – use sudo fdisk -l to see all partitions on the hard disk. Many distributions specify these partitions by UUID (instead of /dev/sdxy uses UUID = …………….), which can eliminate the errors caused by their numbering – to see which is UUID, for each partition use the sudo blkid command. When Linux encounters this entry, it tries to find the partition specified by the name or UUID and mount it.

Dir – or mount point. The second column specifies the location in the directory tree structure where the indicated partition will be mounted. This is usually a previously created empty directory (the root partition (/) is an exception – in the example shown, partition / is /dev/sda9). We also have a swap partition that does not have a mount point.

Type – file system type. It is a code that indicates what type of file system is on that partition. The auto option lets the kernel automatically detect the file system. Automatic detection does not work with all types of file systems – ntfs partitions.

Options – mount options (identical to those from the mount command). Modifies how the kernel will handle these file systems. The options used in fstab can be found using the man mount command.

Dump – backup operations. It specifies whether or not the dump utility backs up the partition (1 – for backup, 0 – does not backup). If you have never used the dump program, this option is no longer worthwhile – dump was once a very useful backup utility, but it is now almost no longer used.

Pass – Checking the integrity of the file system. When booting the system, Linux uses the fsck utility to check that partition. The last column (the sixth) specifies the order in which this verification will take place (the possible values are 0, 1 and 2): 0 means that the partition will NOT be verified; the root partition (/) must be 1 (first checked), all other partitions requiring verification will have a value of 2.

If you add a new hard drive to the system, you will also need to change the fstab file.

Knowing all of this, deciphering and editing the /etc/fstab file will no longer be a problem for anyone.

Recent Posts

Archives

Categories