Introduction and Working of Linux /etc/fstab File
Linux /etc/fstab File
The /etc/fstab is a file that contains all the information about partitions and storage devices present on the system. This file is basically located under the “/etc/” directory.
This file gives you information about where your storage devices should be mounted.
FSTAB is a very critical and important file present in “/etc” directory where all the configuration files stored.
It is the responsibility of SysAdmin to properly create and maintain this file.
In this tutorial, we are going to understand the structure of /etc/fstab file before writing anything into the file. Because if you add something with the wrong format or structure it will result in crashing your system. You need to handle /etc/fstab file very carefully.
Important points keep in mind before adding anything to /etc/fstab file,
- Each filesystem is described or written on a separate line.
- Fields on each line to be separated by tabs or spaces.
- Lines started with “#” are comments.
- Most important are the order of records which is like fsck, mount, umount, etc. explains further in deep.
If you are new to Linux and don’t see /etc/fstab file before then see the below image of /etc/fstab file for understanding,
A total of Six columns are present in /etc/fstab file. Each column defines or performs a different role. To add or mount a new device use a new row.
Let’s understand the working of Each Column one by one
First field – The block device
The first column will define the “Label” of partitions.
For Eg. “LABEL=/boot” OR Driver’s path, Eg. “/dev/cdrom”.
The device driver’s path tells the system to mount the device with the mentioned device driver.
Second field – The mountpoint
The second column describes the mount point for the filesystem. There are some filesystem should be specified as ‘none’ like swap partition.
The mount point is actually the name of the directory where that device is mounted.
Using this mount point we can be able to view and modify the content of that partition.
You can modify the mount point according to your requirement.
Suppose we want to mount our filesystem to “/mnt/test”;
Use the following way :
Third field – The filesystem type
The third column will be used to define the Filesystem type of partition or device.
Several no. of filesystems supported by Linux and some of them listed below,
If you are not sure about the filesystem then use the “auto” option.
“auto” will help to determine the file system and mount the device with that filesystem.
UUID=80b296wa-ce1d-4ecf-8afc-asdafdsdf /mnt/test ext4
Fourth field – Mount options
The fourth column is for permissions to be given to the partition at the time of booting. There are many options that constitute the fourth column.
They are as follows: –
1) ro : Read Only
2) rw : Read Write
3) auto : Mount on startup
4) noauto : Do not mount on startup
5) user : Any user can mount, but only unmount device mounted by him
6) nouser : The Only root can mount & unmount the device
7) users : Every user can mount and also unmount the device mounted by others
8) owner : Same as user (above no. 5)
9) dev : User can use device driver to mount the device
10) nodev : User cannot use a device driver to mount the device
11) exec : Users can execute binaries on the partition
12) noexec : Users cannot execute binaries on the partition
13) async : Asynchronous, whenever a file is saved it will be first saved in the RAM and after 30 seconds all the queued files will be written on the hard disk
14) sync : Synchronous, whenever a file is saved it will be directly written to the hard disk
15) suid : Allow set-user-identifier for the device where users are allowed to run binaries even though they do not have to execute permissions. These binaries are temporarily made available to them to perform certain tasks
16) nosuid : Do not allow set-user-identifier
17) defaults : auto, rw, dev, async, suid, exec & nouser
Fifth Field – backup option
This column is used as a backup option.
It will contain two values either 0 or 1. Here 0 stands for “no” and 1 stands for “yes”.
if option 1 used then system checks are enabled at the time of booting and if 0 used then system checks will be ignored.
Backup option supported only ext3 filesystem which means for another filesystem this option should be disabled by default.
Sixth field – Fsck order
The 6th column is using for the “fsck” option.
Fsck stands for filesystem check. This option system will scan the filesystem at the time of the start-up.
Here The / partition is assigned top priority i.e. 1 and the rest of the partitions are assigned second priority i.e. 2. If the value is set to 0 means no scanning will be done at the time of startup.
If the same number is given to different partitions then the partitions are scanned together with equal priority.
This minimizes error because if a link is present on one partition with higher priority and the source file in another partition with a priority lower than the link, it will give an error.
With this last field our example entry is finally complete:
UUID=80b126fa-cas2d-4awcf-9aasfc-bca1a67f1 /mnt/test ext4 defaults 0 2
I hope you like the article if you find any difficulties then please do comment your queries or problem via the comment section, till then stay tuned to Linuxgrow.com for more such valuable articles.