What is the use of the /etc/fstab file in Linux?

In this article, you will learn about what is the /etc/fstab file in Linux?

The fstab file in Linux is a configuration file to mount any other device to a directory to get information from that device and making that device mount point permanently so even after rebooting the computer, we no need to mount it again to get that information.

In simple words, we are making the mount point permanently for that device. The fstab stands for the filesystem table. And the location of this file is /etc/fstab.

This /etc/fstab file is created automatically at the time of the operating system installation. You can modify the information in fstab with the help of any text editor.

If you want to modify the information in fstab, then you must have root access. If you are a regular user, then you can only see the information in it, which means read-only mode.

How to get help for the fstab file

I always suggest reading the manual page. It will give you an in-depth introduction to this file.

So, to get the manual page type the below command,

man fstab

To view the information in fstab safely, you can use the cat command,

cat /etc/fstab 

(after typing this command you can see like below picture)

fstab file in linux
Viewing fstab file using the cat command

You can see that the file contains one line with six fields for each mounted filesystem.

UUID=82237e0f-0dbe-4277-9f0e-1472c7619df1 /boot xfs defaults 0 0

1. The physical location of the filesystem

The first field shows the physical location of each filesystem, which can be a partition on the hard disk or it can be a separate device such as a floppy disk, CDROM, Pendrive (flash drive), or any other device. If you look at the partition, then you see that generally it is listed in the order in which they are located on the hard disk.

If there are two hard disks, then all the partitions on the first one will be listed first. You can see the name of the device file, or the file system label, or the UUID (Universally Unique Identifier). In the above picture, you can see the UUID of that filesystem, like UUID=82237e0f-0dbe-4277-9f0e-1472c7619df1

2. The mount point

The second field shows the mount point. You can put the location of that directory where you want to mount it.

The directory name where you want to mount it must already exist. If it is not then first to create the directory and then mount it. In the above picture, you can see the mounted directory name as /boot

3. The filesystem type

The third field shows the filesystem type. Here we mention the partition or device format type.

So, many of the modern Linux version supports a large number of filesystem types, Some of them ext2 (the primary Linux filesystem type), ext3 (an enhanced version of ext2 with journaling capabilities), ext4 (an improved version of ext3 with journaling capabilities and modifies important data structure), Reiser (another journaling filesystem),

vfat (which is compatible with some Microsoft filesystems), iso9660 (used by most CDROMs) and nfs (network file system), XFS (high-performance 64-bit journaling file system created by Silicon Graphics). The file which we are looking at in the above picture has been formatted using xfs.

4. Basic security

The fourth field adds some basic security to the system by designating by whom and how the filesystem or device can be used. Multiple mount options are separated by commas (such as noauto, user, sync).

5. Dump command

The fifth field is used to determine whether the dump command will back up the filesystem. zero (0) means no backup. If it is one (1), it means backup on priority.

6. Filesystem check

The use of the sixth field is to check the filesystem during booting. This uses the fsck program. The three possible values for the column are: 0, do not check, 1, check first (only the root partition should have this setting) and 2, check after the root partition has been checked.


Changing the values in the fstab file

If you want to change the value in /etc/fastab, you can do that but be sure whatever entry you are doing there. To update the fstab file, you must log in with the root user and use a text editor like vi or vim.

vim /etc/fstab
fstab file in linux
Changing the fstab content using the vim editors

Note: To reflecting the changes in fstab without rebooting the system, you can run the mount command.

mount -a

Firstly, to check the UUID and filesystem type you can type the below command,

blkid
blkid command
Checking UUID using the blkid command

Secondly, to check mount point, you can use lsblk or mount command, see the below output of lsblk

lsblk
lsblk command
Checking mount point using lsblk command

Conclusion

In conclusion, you learned about the /etc/fstab file Linux. It is an essential file for mounting permanently. So, I hope, you understand, but if you have any questions, you can ask in the comment section.

Also, you can read

One comment

Leave a Reply