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.
How fstab is Structured
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 itsLABEL
orUUID
(Universal Unique IDentifier). The latter is the preferred method since it guarantees to univocally reference a filesystem. OnGPT
partitioned disks it’s also possible to reference a filesystem by usingPARTUUID
orPARTLABEL
.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 usuallyrw, 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 thatfsck
will not check the filesystem. Numbers higher than this represent the check order. The root filesystem should be set to1
and other partitions set to2
.
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.
Hands-on Exercise Overview
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.
Hands-on Exercise
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
💡Choose/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
💡Without this directory exists, thefstab
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 thefstab
file and the system knows that this directory is associated with the device/dev/sdc
. Thus, themount
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.💡The optionnoauto
in the mount options field of thefstab
file does not mount whenmount -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.