TLDR
The choice between fstab and systemd depends on factors like the desired boot performance, complexity of the system’s requirements, and administrator familiarity. For simpler setups or when working with familiar, well-established methods, fstab might be a suitable choice. On the other hand, for more dynamic and complex configurations, as well as a desire for faster boot times, systemd offers advantages. It’s important to carefully consider your system’s needs and your own familiarity with the tools when making a decision.
The /etc/fstab File
Some distributions, especially older ones, rely on the /etc/fstab file to mount partitions. Systems that use systemd still have and reference /etc/fstab, but they supplement its settings.
The system reads /etc/fstab during startup. Partitions defined are identified and mounted to the filesystem at the specified locations. The file is edited with a standard text editor, but you must be careful not to make typographical errors.
A sample entry in the /etc/fstab file for the /projects directory might look like this:
/dev/sdb2 /projects xfs rw 0 2
The /etc/fstab file is divided into six fields.
stab Field | Value |
---|---|
Block device | Drive and partition |
Mount point | Where the partition is mounted |
Filesystem type | The filesystem on the partition (XFS or ext4) |
Mount options | Read-write or read-only options, others |
Dump | Whether dump program backs up partition (1 or 0) |
FSCK order | Order fsck checks partitions (1 for root, 2 for all others) |
During system startup, the kernel reads /etc/fstab and mounts the specified partitions to the listed mount points.
In the fstab (file systems table) configuration file on Linux systems, defaults refer to a set of default options that are applied when mounting a filesystem unless explicitly overridden. These default options can vary slightly based on the filesystem type, but generally include a common set of options. Keep in mind that the specifics might differ based on the distribution and version of Linux you’re using, but the following are the common default options you might find in an fstab entry:
Options | Description |
---|---|
rw | Stands for “read-write,” indicating that the filesystem is mounted in a mode where both reading from and writing to it are allowed. |
suid and dev | These options allow setuid and setgid bits to work and permit device files to be executed. |
exec | This option enables the execution of binaries from the mounted filesystem. |
auto | This option indicates that the filesystem should be automatically mounted at boot time, based on the mount -a command or the boot process. |
nouser | Prevents non-root users from mounting the filesystem. Only the root user can mount it. |
async | Specifies that data should be written to the filesystem asynchronously, which can improve performance. However, it might also increase the risk of data loss in case of a sudden system crash. |
relatime | This option updates file access times in a way that doesn’t negatively impact performance compared to the traditional atime option. |
fsck | Specifies the order in which filesystems should be checked by the fsck tool during boot. It’s usually set to a value like 1 for the root filesystem and 2 for others. |
errors | Defines the behavior when errors are encountered during mount. The default is often set to remount-ro, which remounts the filesystem read-only in case of errors. |
discard | This option enables the use of the TRIM command for SSDs and other flash-based storage, helping to manage the storage’s wear and maintain performance over time. |
nobootwait | In some configurations, prevents the boot process from waiting for the filesystem to be mounted successfully. This can be useful to avoid boot delays if the filesystem is not essential for booting. |
Remember, these defaults might vary based on the filesystem type and Linux distribution. Always consult the official documentation for your specific distribution or the man page for fstab (man 5 fstab) to get accurate information on the defaults used in your environment.
USE CASE: Mount a new partition onto /home directory
REQUIREMENT: before mounting a device a storage device must be [[partitions|parted]] and file system must be [[make-file-system|created]]
- copy /home directory with a different name in a different location
$ sudo cp -p -r /home /home-bkp
- delete content in /home
$ rm -rf /home
- open /etc/fstab and set automount settings
#mount m.2 disk (/dev/nvme0n1) in /home directory
/dev/nvme0n1p1 /home ext4 defaults 0 0
- mount storage
$ mount -a
- check whether storage was mounted
$ mount | grep /dev