Categories: Disks and Partitions

Linux fstab file (disk mount setup) [Basic Guide]

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
Auto Enables the device to be mounted on the operating system load.
noauto Disables the device from being mounted on the operating system load.
ro Mount the file system as read-only.
rw Assemble the file system for reading and writing.
exec Enables the execution of files on the specified file system.
noexec Disables file execution.
user Enables any user to assemble the device.
nouser Only the superuser can assemble and disassemble the device.
sync Enables synchronous data transfer on the device.
async Enables asynchronous data transfer on the device.
dev Special character device.
suid Enables executables to have suid and sgid bits and execute as if they were the superuser.
nosuid Disables executables from containing suid and sgid bits.
defaults Configure mount options such as rw, suid, exec, auto, nouser, and async.

/etc/fstab example:

$ 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 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.

Uirá Endy Ribeiro

Uirá Endy Ribeiro is a Software Developer and Cloud Computing Architect with a 23-year career. He has master's degrees in computer science and fifteen IT certifications and is the author of 11 books recognized in the IT world market. He is also Director at Universidade Salgado de Oliveira and Director of the Linux Professional Institute - LPI Director's Board.

Uirá Endy Ribeiro

Uirá Endy Ribeiro is a Software Developer and Cloud Computing Architect with a 23-year career. He has master's degrees in computer science and fifteen IT certifications and is the author of 11 books recognized in the IT world market. He is also Director at Universidade Salgado de Oliveira and Director of the Linux Professional Institute - LPI Director's Board.

Recent Posts

Sudo command on Linux (privilege scale) [Basic Guide]

The sudo command on Linux executes a given command as if it were another user.…

2 years ago

SS command on Linux (investigate the network) [Basic Guide]

The ss command on Linux is extremely useful for investigating sockets, providing various information about…

2 years ago

Free Linux command (memory usage) [Basic Guide]

Free Linux command shows the amount of total memory in use and available, as well…

2 years ago

Linux while command (loop – while) [Basic Guide]

The shell has structures for testing conditions and executing certain program sequences several times (loop),…

2 years ago

Netcat command on Linux (Swiss network knife) [Basic Guide]

The Netcat Command in Linux or nc is a utility used to do “almost anything”…

2 years ago

Linux gdisk command (partitioning disk) [Basic Guide]

The gdisk command in Linux is similar to fdisk and allows you to manipulate and…

2 years ago

This website uses cookies.