What Is Linux fstab File and How Can We Configure It? – POFTUT

What Is Linux fstab File and How Can We Configure It?


Linux operating system relies on files. File systems should be mounted in order to be used. Mounting a file system can be with the mount command. In order to mount single or multiple file systems, we need some configuration. There is default configuration while using mount. But if we want to provide different options about mount we can use /etc/fstab file. In fstab we can provide information about the mount and automatically mounted files with during boot.

/etc/fstab File

fstab file is stored under the /etc directory. /etc/fstab file is a simple column based configuration file where configurations are stored as column based. We can open fstab with the text editors like nano, vim,Gnome Text Editor, Kwrite etc. but if we want to save the changes we made we require to get root privileges with the sudo command.

$ sudo nano /etc/fstab
/etc/fstab File
/etc/fstab File

After providing the password for the user ismail to get root privileges with sudo command we will see following fstab file content

/etc/fstab File
/etc/fstab File

Comment

Before starting the detailed configuration about fstab we need to learn comment. In the previous screenshot, we see the turquoise lines those are comments. So lines starting with the # are comments. We can provide comments about newly created or changes configurations between configuration lines.

# This is comment

fstab Columns

As stated previously fstab file consists of columns which stored configuration options. Each row contains a single configuration record to mount and each column in this row contains different configuration options.

fstab Columns
fstab Columns

Here is sample configuration row or record.

UUID=e1ea69a0-7566-4002-a47d-3a93d1ebfb96 / ext4 errors=remount-ro 0 1

Each configuration columns is defined in the comment line which starts <file system.

fstab Columns
fstab Columns

We can see that the following configuration column is provided where we will explain them in detail.

  • `File System` is the source which we want to mount
  • `Mount Point` is the destination we want to mount
  • `Type` is the file system type of the `File System`
  • `Option` is used to specify the behavior of the mount
  • `Dump` specifies whether the file system will be dumped in the error case
  • `Pass` sets whether the file system check will be performed
LEARN MORE  Compare FAT32 vs exFAT vs NTFS File Systems

File System Column

We will start with the first column which is used to specify the source file system device. Source file system device can be expressed in 2 different ways. The first way is specifying the path of the partition like /dev/sda1. As dev path is used to store device information. Another way to specify the source file system is providing the UUID information like UUID=e1ea69a0-7566-4002-a47d-3a93d1ebfb96.

File System Column
File System Column

We can see that /dev/fd0 is the floppy disk.

We can find the UUID of a disk with the following blkid command which is shot form of Block ID. We should run with the sudo.

$ sudo blkid
blkid list UUID
blkid list UUID

Mount Point or Dir Column

The second column specifies the path the source will be mounted. Generally, ile system root is specified as / . In this following screenshot, we can see that /dev/sda1 is mounted to the /.

Mount Point or Dir Column
Mount Point or Dir Column

We can see that /dev/fd0 is mounted to the /media/floppy0. The following mounts are also popular in the Linux world.

  • `/mnt` is used to mounted external hard disk drives or USB.
  • `/boot` is used to mount boot partition and the kernel.
  • `/home` is used to mount users home directories

File System Type Column

Up to now, we have specified the source and destination partitions and locations. But as we know there are a lot of different file system types which is supported by Linux. ext4, ext3,fat,ntfs are some of them. In the file system type column, we can specify the file system with a single word.

File System Type Column
File System Type Column

We can see that in this example we are using ext4 and auto filesystems. auto is used to find source partition file system type automatically which can be used in some cases or different file systems like CDROM.

Options Column

Options column is the most comprehensive part of a fstab record. We can specify different behavior options int this part like automount, read-only, noatime etc.If there are multiple options we can delimit them with a comma. Here is an example of options column.

We can see that errors=remounte-ro is provided in the first line. Also rw,user,noauto,exec, utf8 is provided with comma delimiter.

  • `auto/noauto` is used to specify automatically mount given file system on boot. We can also block automount with the `noauto` option during boot.
  • `exec/noexec` is used to set mounted file system files to be executable. If we set to `noexec` the executables in the given file system will not be executed. This can be used to make user home directories `/home` more secure.
  • `ro/rw` is another useful option where we can make file system read-only or read-write. If we do not want to enable file, folder changes and removal we can mount read-only with the `ro` . But in most cases `rw` will be the best solution where we can change file system contents.
  • `sync/async` option is used to specify file system and disk synchronization. This option generally used to make file system more performative. If we select `sync` the changed content will be saved to the disk immediately which create some overload but will be more reliable. `async` will make write operation to the disk more flexible and more performative.
  • `nouser/user` is another important option. By default, normal users cannot mount a file system with the `mount` command and needs `root` privileges to mount. This is depicted with the `nouser`. If we want to normal user mount given file system we should provide `user` option which will enable a normal user to mount given file system.
  • `defaults` is a generic options wich is used in most of the cases which provides default options like `rw,suid,dev,exec,auto,nouser,async`
  • `noatime` option is used to disable access time information to be written to the file system. Disabling access time will boost the disk performance.
  • `suid/nosuid` option is used to allow `suid` and `sgid` bits.
LEARN MORE  How To Use Fsutil To Check and Repair File System In Windows?

Dump Column

Dump column is used to specify whether the there will a dump in an error event. This is designed in the old times and should be set to 0. 1 means enable dumping.

Pass Column

File systems can be corrupted in different situations like disk hardware problem, electricity problem or software bug. This requires a  file system check. We can enable an automatic fsck by setting 1. We should enable fsck for the root / file system. But we can skip for file systems likeNTFS and FATautomatic file system check during reboot which can be accomplished after the start.

Mounting All File Systems In fstab

mount command is used to mount file systems in fstab. We can mount all filesystems given in fstabby using -a or  --all option. Only the noauto file systems will be skipped and not mounted. Mount command will skip already mounted file systems too.

$ sudo mount -a

Umount File System

We can also mount an already mounted file system with the umount command. We just need to provide the file system or mounting point. In this example, we will umount /mnt.

$ sudo umount /mnt

uid or UUID Identifier

Harddisks or Partitions can be specified with the UUID or Unified Unique Identifier. This makes mount operations more stable because as its name suggests every disk or partition on the each will have a unique UUID. So they can not overlap accidentally. We can list uid with the following command.

$ sudo blkid
uid or UUID Identifier
uid or UUID Identifier

We can see that partition named /dev/sda1 has e1ea69a0-7566-4002-a47d-3a93d1ebfb96 as UUID.

noatime Mount Option

Performance is a very important factor in computer usage. The disk is one of the most important parts of computer performance. We can increase the performance of the file system or disk by skipping unnecessary disk operations like metadata storage. noatime will disable to store access time about file and folders in a file system.

LEARN MORE  How To Use Chkdsk /F Command?

 

Leave a Comment