Linux fstab: Automatic Disk Mounting Guide
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 |
| auto | Enables the device to be mounted during operating system boot. |
| noauto | Disables the device from being mounted during operating system boot. |
| ro | Mounts the file system as read-only. |
| rw | Mounts the file system for reading and writing. |
| exec | Enables the execution of files on the specified file system. |
| noexec | Disables the execution of files. |
| user | Allows any user to mount the device. |
| nouser | Only the superuser can mount and unmount the device. |
| sync | Enables synchronous data transfer on the device. |
| async | Enables asynchronous data transfer on the device. |
| dev | Character special device. |
| suid | Enables executables to have suid and sgid bits and run as if they were the superuser. |
| nosuid | Disables executables from having suid and sgid bits. |
| defaults | Configures 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
That was just one piece. The course teaches the whole path — from your first command to exam day.