Skip to content

Linux fstab file (disk mount setup)

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

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

  • Device: Specifies the device to be mounted. It can be device name in /dev, UUID, or LABEL;
  • Mount Point: Specifies the directory where the device will be mounted;
  • File System Type: Specifies the type of file system to be mounted;
  • Mount Options: Specifies mounting options depending on the type of file system;
  • Backup Frequency: The dump program queries the file to find out the Backup frequency. It is a numeric field, where 1 is for ext2 systems and 0 for others;
  • Disk Check: determines whether or not the device should be checked under system load by fsck. It is a numeric field, where 0 is not to be checked, 1 is to be checked first (root system) and 2 to check 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 of these fields for the registration in /etc/fstab to be correct.

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

Available mounting options are:

**Option****Description**
AutoEnables the device to be mounted on the operating system load.
noautoDisables the device from being mounted on the operating system load.
roMount the file system as read-only.
rwAssemble the file system for reading and writing.
execEnables the execution of files on the specified file system.
noexecDisables file execution.
userEnables any user to assemble the device.
nouserOnly the superuser can assemble and disassemble the device.
syncEnables synchronous data transfer on the device.
asyncEnables asynchronous data transfer on the device.
devSpecial character device.
suidEnables executables to have suid and sgid bits and execute as if they were the superuser.
nosuidDisables executables from containing suid and sgid bits.
defaultsConfigure mount options such as rw, suid, exec, auto, nouser, and async.

/etc/fstab example:

$ cat /etc/fstab <br></br>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 one, the UUID notation, has the file system xfs, with default options. Another /dev/xvdf disk was mounted as the system’s /home directory, using ext4.

In addition, /etc/fstab contains information about the partition used as swap. In this case the mount point will be swap and 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 goes back to all devices configured in /etc/fstab.

It is common to use the UUID of the disks in /etc/fstab in order to prevent the disk name in /dev/ from being changed due to a change in hardware, such as the insertion of a new disk.