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** |
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:
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.