What is fstab in Linux and what are entries of /etc/fstab file

Often Linux System Administrators come across /etc/fstab file and it is frequently asked in interviews about this file and the entries/fields of this file. It is very important configuration file that deals with mounting of partitions or file systems on a Linux Machine. This file is created during OS installation and you need to modify this as per you requirements. All the disk partitions created during installation are configured to mount automatically, however for file systems or partitions added later, we need to make changes in the /etc/fstab file to ensure that they are configured to mount automatically during system boot up.

In Linux, each device is available in the default path /device. Whenever you plug a USB or connect any other external device  to a Linux System, you need to mount the device to access the contents of it. Lets take another example, suppose if you want to mount a nfs share on your machine, you can mount the same using mount command. However if you reboot your machine, you will see that the nfs share/mount point is no longer accessible. Here /etc/fstab comes into picture. To make the mounting of File systems persistent so that they are available even after the machine reboot, we need to add entry of the same in the fstab file.

Fstab file path


Fstab File example

Below is the example of /etc/fstab file of my system

In the above fstab screenshot you can see that there are six fields in fstab file.
i will take example of  / file system 
/dev/mapper/rhel-root    /                xfs     defaults        0 0

First Field 

First field  (/dev/mapper/rhel-root ) in the /etc/fstab file corresponds to the partition or the device name, here in our case it is the  root partition (/dev/mapper/rhel-root) mounted on / and configured using LVM (Linux Volume Manager).  Many times you will notice that the first entry is UUID of partition or file system, like in our case /boot file system is having first field as its UUID.
UUID (Universally Unique Identifiers) is always better option to choose instead of writing disk names like /dev/sdx as UUID of a partition never changes.
You can list the  disk uuids using “ls -l /dev/disk/by-uuid” or “blkid” command.
For nfs file system the first field will be like 
<NFS-share-Ip-address or dns>:/share-path
If you have plugged in external device and want to know the device name, you can check the same in the /var/log/messages.

Second Field 

Second field in /etc/fstab specifies the mount point or the location on the Linux system  where file system will be mounted. Make sure that the directory exists in the system that will serve as mount point.

Third Field 

Third Field in the fstab is for file system type. Like it is xfs in our case. Some common file system types are :
  • ext3 / ext4 / xfs  :  extended file systems 
  • swap : Used for swap memory partitions.
  • nfs : used for Network file systems
  • iso9660 : this is used for mounting iso/dvds
  • ntfs : windows partitions are mounted as ntfs
  • auto : in case third field is set as auto, then file system type is detected automatically.

Fourth Field

Fourth Field is for mount options,  we can choose different mount options that will impact how a  file system will be mounted. It can be confusing for newbies however a professional Linux system administrator should have knowledge of  these mount options and choose them accordingly for mounting the partitions.
Below are the list of mount options available.
  • ro/rw : option “ro” is used for mounting  partitions or file system as read only and “rw” option will mount the partition as read write.
  • exec/noexec : This is very important option  and used to specify whether the partition can be used to execute binaries. 
  • auto/noauto : Specifies whether the partition or device should be mounted on boot. If case it is set as “auto”, then it will mount that file system at boot, else “noauto” will exclude that partition from getting auto mounted at system boot-up.
  • sync/async : sync refers to synchronously, that means whenever data is written for sync mount points, writing is done immediately. For async, the changes will be written at the time on unmounting of device. 
  • nouser/user : in case user is set, then users will be able to mount the partitions or file system, else nouser will allow only root user to mount the file system.
  • suid/ nosuid :  if  nosuid is set and mount point contains suid files, then they will be ignored.

Fifth Field

Fifth field in the fstab file can have two options 0 or 1 and it for backups using dump backup utility
  • 0  : 0 is for false and if set, it will disable the dumping and that partition will be excluded from backing up partitions using dump utility.
  • 1 : 1  is for true and if set, it will enable the dump utility to take backups for that partition.

Sixth Field 

Last and Sixth Field is used for fsck that is for File System Check Order at the boot time.
  • 0 :  If a partition or file system is having value 0, then that partition will be skipped/excluded from file system check at boot time. Normally for nfs and ntfs file systems it is set as 0.
  • 1 : Value 1 will be the first partition that will undergo fsck during boot time. Root file system is always mounted with 1 as fsck option so that fsck  runs on it first followed by other file systems.
  • 2 : Remaining File systems that need to checked should have value 2