The /etc/fstab file on Linux Explained

To use a hard disk partition or external file system, we need to mount it on the Linux file system. There are two ways to mount a disk partition or external file system: temporary and permanent. We use the mount command to mount it temporarily and the /etc/fstab file to mount it permanently.

The /etc/fstab file stores mount points' information. The kernel reads this file at the boot time to mount partitions to the Linux file system. If we want to mount a partition permanently, we must create an entry for that partition in this file.

A fstab file entry has six fields. The following table explains their meanings.

Field Description
First It describes the device or partition's name we want to mount.
Second It describes the mount point's name.
Third It describes the file system of the partition.
Fourth It describes the mount options.
Fifth The dump command uses it to determine whether it should dump the mounted partition at the boot time.
Sixth The fsck command uses it to determine whether it should check and repair the mounted partition at the boot time.

Using the /etc/fstab

Let us take an example to understand how to use the /etc/fstab file to mount partitions permanently.

Suppose you attached a new hard disk to the system and created partitions. You can use the fdisk -l command to list partitions on a disk. The following image shows a new hard disk with partitions.

the fdisk l command

Now suppose, you want to mount these partitions permanently. To mount a partition permanently, you need to create an entry in the /etc/fstab file. The kernel reads and uses this file at the boot time to mount partitions.

the fstab file

Before we create entries for our partitions, let us take the backup of the current file. A backup copy allows us to restore the system to a working state if we make any mistakes.

creating backup

To mount a partition, we need a directory. To mount four partitions, we need four directories. Create four directories.

making directory

Open the /etc/fstab file and create entries for the partitions at the end of existing entries.

default fstab file

In the first field, specify the absolute path of the partition you want to mount.

the first field of the fstab entry

In the second field, specify the directory on which you want to mount the partition specified in the first field.

the second field of the fstab entry

In the third field, you need to specify the partition's file system.

the thrid field of the fstab entry fstab

The fourth field describes the mount options associated with the filesystem. For practice, you can use the default option here.

the fourth field of the fstab entry fstab file

In the fifth and sixth fields, use a value of zero.

The dump command uses the fifth field to determine whether the mounted device or partition needs to be dumped during the boot time.

the fifth field of the fstab entry the fstab file

The fsck command uses the sixth field to determine whether it should check the file system on the mounted partition or device.

the sixth field of the fstab entry

To enable these options, we need to use a value of one in these fields. If we enable these options, it will improve system performance and increase the boot time. You can turn these options on or off on a production system based on your requirements. Since we created these partitions only for practice, we do not need to enable these options.

Save the file.

saving the fstab file

To test these partitions, restart the system.

restarting the system

The kernel reads the /etc/fstab file to mount partitions at boot time. If it fails to mount any partition, it halts the boot process. If the system boots normally, it verifies all partitions specified in the fstab file have been mounted successfully.

After restart, we can use the lsblk command to list partitions.

the lsblk command

As we can see in the above output, all partitions are mounted successfully. It verifies the /etc/fstab file entries.

This tutorial is part of the tutorial series Linux disk management concepts and configurations. Other parts of this series are the following.

Chapter 01  Linux disk management terminology
Chapter 02  File Management Commands in Linux
Chapter 03  Linux file system types explained
Chapter 04  Adding and removing hard disks in VMware Workstation
Chapter 05  List view and find hard disk names in Linux
Chapter 06  The fdisk command on Linux explained
Chapter 07  Manage Linux disk partition with the gdisk command
Chapter 08  The /etc/fstab file on Linux explained
Chapter 09  Linux disk management with the parted command
Chapter 10  The mkfs command on Linux
Chapter 11  The mount command on Linux temporary mounting
Chapter 12  The swap space on Linux explained
Chapter 13  How to create a swap partition in Linux
Chapter 14  How to configure LVM in Linux step-by-step
Chapter 15  How to configure RAID in Linux step-by-step

Conclusion

The /etc/fstab file saves information about partitions. The boot process reads this file to mount partitions on the file system. It is a regular text file. You can edit or update this file based on your requirements.

ComputerNetworkingNotes Linux Tutorials The /etc/fstab file on Linux Explained

We do not accept any kind of Guest Post. Except Guest post submission, for any other query (such as adverting opportunity, product advertisement, feedback, suggestion, error reporting and technical issue) or simply just say to hello mail us ComputerNetworkingNotes@gmail.com