The /etc/fstab file in Linux

Postgraduate in Communications Engineering with working experience in the Support Desk and self-study in software development.
Search for a command to run...

Postgraduate in Communications Engineering with working experience in the Support Desk and self-study in software development.
The find command in Unix is a powerful utility used for searching files and directories based on various criteria such as name, type, size, permissions, modification time, and more. It recursively descends into directory trees and matches conditions ...
The git log command is used to view the commit history of a Git repository. You can customize the output format to show specific details in a more readable or structured way. Below are some useful variations and formatting options for git log: To sh...

Overview This article will teach us how to: Install Ubuntu Server 24.04 on a laptop from scratch Install Ubuntu server by using Vagrant tool with ISO image Prerequisites: A laptop without any OS installed; A virtualization software Virtualbox t...

The /etc/passwd and /etc/shadow files are the backbone of Linux user management. Together, they store user account information and handle authentication securely. This article provides a hands-on guide to understanding these files, their structure, a...

In Linux, links are powerful tools that allow you to create references to files and directories. There are two main types of links: hard links and soft links (also known as symbolic links or symlinks). Understanding the differences between these two ...

A hostname is a human-friendly name given to a computer. It is a unique identifier that allows us to identify the machine in various network communications, making it easier to locate and manage devices. Type: hostname To see where it is stored, typ...

The fstab file in Linux stands for "filesystem table" and is commonly found in the /etc directory. It typically lists all available disk partitions and other types of file systems, their mountpoints and mount options. fstab is meant to be only read by programs and never written except by the system administrator. It is read by the mount command, which happens automatically at boot time to determine the overall file system structure, and thereafter when a user executes the mount command to modify that structure. The system administrator has to properly create and maintain this file.
The table itself is a 6-column structure, where each column designates a specific parameter and must be set up in the correct order. The fields of the table are as follows from left to right:

Block device - the device that should be mounted. The most typical way to reference a block device is by using its location /dev/sda1 or by using its LABEL or UUID (Universal Unique IDentifier). The latter is the preferred method since it guarantees to univocally reference a filesystem. On GPT partitioned disks it’s also possible to reference a filesystem by using PARTUUID or PARTLABEL.
Mount point - specifies the mountpoint for the filesystem. It is a directory in the system that should be used to access its content. This should always be provided except if the block device is used as a swap. In that case "none" should be used.
Filesystem type - the type of filesystem in use on the raw block device or partition. Linux supports many filesystem types: ext4, xfs, btrfs, f2fs, vfat, ntfs, hfsplus, tmpfs, sysfs, proc, iso9660, udf, squashfs, nfs, cifs, and many more.
Mount options - a list of options when mounting the filesystem. To use the default set of mount options we specify defaults as a value. The kernel default is usually rw, suid, dev, exec, auto, nouser, async.
suid - respect SETUID and SETGID bits;
exec - allow executing binaries and scripts;
noauto - do not mount when mount -a is given (e.g., at boot time);
user - allow a user to mount;
nouser - make the filesystem not mountable by a standard user;
async - perform I/O operations on the filesystem asynchronously;
owner - allow a device owner to mount;
nofail - do not report errors for this device if it does not exist.
Dump - enable (1) or disable (0) the backing up of the device/partition. The value is used by the dump backup program (if installed) to know what filesystem should be dumped. Usually, this field is set to 0, which disables it.
Pass - establishes the order by which another utility, fsck should check filesystems on boot. 0 means that fsck will not check the filesystem. Numbers higher than this represent the check order. The root filesystem should be set to 1 and other partitions set to 2.
An example of fstab table on a Vagrant Ubuntu virtual machine.

Each filesystem is described on a separate line. Lines starting with '#' are comments. Blank lines are ignored. Fields on each line are separated by tabs or spaces.
The main purpose of this hands-on exercise is to gain practical experience in configuring filesystem mounts using the /etc/fstab file. This hands-on shows how to add a new entry to the /etc/fstab file to mount a filesystem and tests the configuration by mounting and unmounting the filesystem.
Run the command that allows us to find out whether there are storage volumes that are not mounted:
lsblk

To get a listing of mounted devices and find out whether our disk device is mounted or not, run:
mount | grep sdc

/mnt directory for permanent storage to mount the disk.To add a new entry to the end of the /etc/fstab file:
sudo vim /etc/fstab
/dev/sdc /mnt/mydisk ext4 defaults 0 0

To create the directory for the storage volume to be mounted:
sudo mkdir /mnt/mydisk
fstab file would not be able to find it and it will cause the problem.To mount the device manually, run:
sudo mount /mnt/mydisk

This command assumes that the details of what to mount (like the device or remote filesystem) are already specified in the /etc/fstab file. The target directory /mnt/mydisk was found in the fstab file and the system knows that this directory is associated with the device /dev/sdc. Thus, the mount command was simplified.
To unmount the device, run:
sudo unmount /mnt/mydisk

To ensure the new entry mounts correctly by simulating the boot-time mounting process, run:
sudo mount -a

This command automatically mounts all filesystems specified in the /etc/fstab file without requiring further human interaction. By running this command, you instruct the system to read /etc/fstab and mount all listed filesystems according to the defined parameters, making it useful for ensuring all necessary filesystems are mounted, especially after a system reboot.
noauto in the mount options field of the fstab file does not mount when mount -a is given (e.g., at boot time). There are several reasons to use this option. 1. It allows you to control when these filesystems are mounted. 2. It simplifies the mount command since there is no need for the device name, and only the target directory can be referred to.To find out the UUID of the storage volume, run:
sudo blkid

It is recommended to use the UUID (Universally Unique Identifier) of a storage volume instead of the device path (like /dev/sdc) in the /etc/fstab file, because UUIDs are unique and remain constant while device paths can change depending on the order in which devices are detected by the system.
ro since it prohibits writing or deleting the storage volume.