How to Make an Entry in fstab in Linux

Fstab stands for File System Table, which is a system configuration file. This file is known as one of the most critical files in any Linux distribution because it handles the mounting and unmounting of file systems to the hardware. When you attach a new Hard Drive or SSD, you need to edit the fstab file to mount it and integrate it into the file system. So, when making an entry in fstab in Linux, we first need to understand the structure of the fstab file.

Fstab File Format

Fstab file is placed in /etc directory, which contains an entry for each file system, and each entry consists of six columns or fields. Since the entries are shown in the tabular form, it is known as File System Table.

To open up the fstab file in any Linux distribution, you can use any text editor to make an entry in the fstab file. We will use a nano editor for opening the fstab file. The command for opening and editing the fstab file in the /etc directory is:

Each column in the entry represents some specific information about the file system. Let’s have a look at an entry and have a brief discussion on each column.

The first field represents the file system.

The second field represents the mount point.

The third field represents the type of file system.

The fourth field represents the mount options.

The fifth field represents the dump.

The sixth field represents the pass.

Now let’s see what they mean and how to make an entry in the fstab file.

File System

It usually contains the UUID or the name of the mounted block device. To make a new entry, we first need to provide the Universe Unique Identifier(UUID) or label of the block device.

To know the UUID or label of the disk that you want to add as an entry in the fstab file, type the command given below:

To add any disk, get the UUID  or label of that disk and paste it as the first field of an entry in the fstab file.

Mount Point

The second field is to provide the path of the directory used by the system to access it. It is also mentioned in the details provided by the command:

Type

In the third field, we need to provide the type of file system like ext4, swap, NTFS, etc. The file type of the disk is also available in the ‘lsblk’, and it can be accessed from there:

Options

In the fourth field, you need to provide the list of mount options that you want to give when mounting the file system. To know what mount options are available and what to give, you can get all the list of mount option from the man page of mount using the command given below:

Suppose you want to set the default options like read-write(RW), suid, dev, exec, auto, nouser, and async. You can simply write defaults in the fourth field. However, if you are going to provide multiple mount options, separate them using commas.

Dump

The fifth field is for the backup option. Here we mention whether the file system should be dumped or not using the binary values 0 and 1, where 0 = No backup and 1 = backup. It is an outdated method now, so you can provide 0 and move ahead.

Pass

In the last field, we need to write the file system check order, also known as the fsck order. This field takes only three values 0, 1, and 2. The value 0 is for not checking the file system and pass, 1 should be set for the root filesystem, and all other partitions should be set to 2. If you do not provide any value, 0 will be selected by default.

Alright, after knowing all the information about a single entry and its fields, now you are fully able to make an entry in the fstab file.

Conclusion

This post provides brief and profound knowledge about the fstab file and explains how to make an entry in fstab in Linux. After reading this post, you can add and mount a hard drive or SSD by making an entry in the fstab file.