fbpx /etc/fstab File on Linux: Mount Disks Automatically at Boot | Certificação Linux

Linux fstab: Automatic Disk Mounting Guide

📅 01/01/2019 ⏱ 4 min ✍️ Uira Ribeiro
Linuxcommands
Linux fstab: Automatic Disk Mounting Guide
Exam Pass App — mais de 7.000 questões LPI, offline, em 5 idiomas, disponível no Android e na App Store
Available on
Google Play
Available on
App Store

The /etc/fstab file stores the configuration of which devices should be mounted and what the mount point of each one is during the operating system boot, even local and remote devices.

The /etc/fstab file configuration contains the following fields:

  • Device: Specifies the device to be mounted. It can be the device name in /dev, UUID or LABEL;
  • Mount Point: Specifies the directory where the device will be mounted;
  • File System Type: Specifies the file system type to be mounted;
  • Mount Options: Specifies mount options depending on the file system type;
  • Backup Frequency: The dump program queries the file to determine backup frequency. It's a numeric field, where 1 is for ext2 systems and 0 for others;
  • Disk Check: determines whether the device should or should not be checked during system boot by fsck. It's a numeric field, where 0 is for no checking, 1 is for checking first (root system) and 2 for checking after the root system.

Fields can be separated by a single space, or TAB.

Each line in /etc/fstab must be a separate mount point and must contain all these fields so that the /etc/fstab entry is correct.

The most common file system types are: ext2, ext3, ext4, reiserfs, xfs, btrfs, vfat, iso9660, nfs, swap, etc.

The available mount options are:

Option Description
autoEnables the device to be mounted during operating system boot.
noautoDisables the device from being mounted during operating system boot.
roMounts the file system as read-only.
rwMounts the file system for reading and writing.
execEnables the execution of files on the specified file system.
noexecDisables the execution of files.
userAllows any user to mount the device.
nouserOnly the superuser can mount and unmount the device.
syncEnables synchronous data transfer on the device.
asyncEnables asynchronous data transfer on the device.
devCharacter special device.
suidEnables executables to have suid and sgid bits and run as if they were the superuser.
nosuidDisables executables from having suid and sgid bits.
defaultsConfigures mount options as rw, suid, exec, auto, nouser and async.

Example /etc/fstab:

$ cat /etc/fstab UUID=8a9e0fcb-f415-4a3f-931d-919fadf8e22c  /     xfs    defaults 0   1
/dev/xvdf                                  /home ext4   defaults 0   1
/dev/xvdg                                  swap  swap   defaults 0   0

In this example, the device that was mounted as root using UUID notation has the xfs file system, with default options. Another disk /dev/xvdf was mounted as the /home directory of the system, using ext4.

Also, /etc/fstab contains information about the partition used as swap. In this case the mount point will be swap, as well as the type will also be swap. This way, when the computer restarts, the swap partition will be automatically enabled with the "swapon" command.

Remember that the mount command with the -a option remounts all devices configured in /etc/fstab.

It's common to use disk UUIDs in /etc/fstab in order to avoid the disk name in /dev/ being changed due to some hardware change, such as for example the insertion of a new disk.

Learn much more about Linux in our online course. You can enroll here. If you already have an account, or want to create one, just log in or create your user here.

Liked it? Share

Uira Ribeiro

Prof. Uirá Ribeiro

Chair do Board do Linux Professional Institute

After years of watching professionals waste hours on simple tasks because they didn't know the right Linux tools, I decided to teach.
Today I'm the author of most of LPI's official Learning Materials and mentor to over 14,000 certified students.

See my full story →

That was just one piece. The course teaches the whole path — from your first command to exam day.

Certificação Linux — a plataforma líder em certificações Linux no Brasil
WhatsApp