The power of fstab

dos2unix

Well-Known Member
Joined
May 3, 2019
Messages
4,408
Reaction score
4,601
Credits
41,638
Understanding /etc/fstab: Mount Options and Boot Behavior — Part 1


Every Linux administrator has typed an fstab entry. Most of us learned by copying an existing line, tweaking the device and mountpoint, and hoping for the best. The file works, the disk mounts, and we move on. But fstab has more depth than that cargo-culted "defaults 0 0" at the end of every line suggests. This two-part article breaks down what you are actually configuring. Part 1 covers the options field. Part 2 covers the dump and pass fields, slow-device timeouts, and a complete real-world example.


The Structure of an fstab Entry


A standard fstab line has six fields:


Code:
<device>  <mountpoint>  <fstype>  <options>  <dump>  <pass>


Most attention goes to the first three. The fourth field — options — is where mount behavior is actually controlled. The fifth and sixth are widely misunderstood and in many cases blindly copied. We will get to those in Part 2.


Device Identification: UUIDs Over Device Names


Before getting into options, it is worth a word on the device field. Using raw device names like /dev/sdb1 is fragile. Device enumeration order can shift when hardware changes, especially on systems with multiple disks or USB storage. A disk that was /dev/sdb yesterday can become /dev/sdc after a reboot with a new drive present.


UUIDs are stable across reboots and hardware changes. Find them with:


Code:
blkid /dev/sdX


Or for a full view of all block devices and their filesystems:


Code:
lsblk -f


An fstab entry using a UUID looks like this:


Code:
UUID=a1b2c3d4-e5f6-7890-abcd-ef1234567890  /mnt/data  ext4  defaults  0  2


It is more verbose, but it will not silently mount the wrong partition after a hardware change.


The Options Field


The options field is a comma-separated list of mount flags. Multiple options can be combined freely. The most common and useful are covered below.


defaults


The word "defaults" is shorthand for a specific set of options: rw, suid, dev, exec, auto, nouser, and async. It is a reasonable baseline for most local filesystems. The important thing to understand is that "defaults" is not a magic word — it is a macro. You can override individual defaults by appending additional options after it. For example:


Code:
UUID=...  /mnt/data  ext4  defaults,noexec  0  2


This gives you the full defaults set but disables execution of binaries on that filesystem.


auto and noauto


The auto option, which is included in defaults, causes the filesystem to be mounted at boot and when someone runs mount -a. This is the normal behavior for system partitions.


The noauto option suppresses that behavior entirely. A filesystem marked noauto will not be mounted at boot and will not be touched by mount -a. It stays unmounted until explicitly requested.


This is more useful than it might seem. Consider a backup disk, an archive drive, or a secondary data volume you only need occasionally. You do not want it auto-mounted every boot, but you also do not want to remember the UUID or device name every time you need it. With noauto and a UUID in fstab, you get the best of both:


Code:
UUID=a1b2c3d4-e5f6-7890-abcd-ef1234567890  /mnt/backup  ext4  defaults,noauto  0  2


Now mounting it is as simple as:


Code:
mount /mnt/backup


The kernel looks up the device, filesystem type, and remaining options from fstab automatically. You do not have to specify anything. When you are done:


Code:
umount /mnt/backup


The disk stays unmounted through reboots until you ask for it again.


nofail


The nofail option tells the boot process to continue even if the device cannot be found or mounted. Without nofail, a missing device listed in fstab can cause the system to drop into emergency mode at boot — a serious problem on a headless server or a remote machine you cannot physically reach.


nofail is especially important for:


— Removable drives that may not always be connected— Secondary data disks that are not required for the system to function— External USB drives included in fstab for convenience— Any device where absence should be a non-event rather than a boot failure


Code:
UUID=a1b2c3d4-e5f6-7890-abcd-ef1234567890  /mnt/backup  ext4  defaults,noauto,nofail  0  2


Note that noauto and nofail complement each other well. noauto prevents the mount attempt at boot, so nofail never even needs to trigger in normal operation. But if something unusual causes a mount attempt — an initramfs quirk, a script calling mount -a, or a systemd unit dependency — nofail ensures a missing device does not become a crisis.


_netdev


The _netdev option is specifically for network-backed filesystems: NFS, CIFS/Samba shares, iSCSI volumes, and similar. It signals to systemd and the init system that this mount depends on the network being available, and that the system should not attempt to mount it until networking is up.


Without _netdev on a network mount, the system may attempt the mount during early boot before a network interface is configured, fail, and potentially stall or drop to emergency mode.


Code:
192.168.1.50:/export/shared  /mnt/nfs  nfs  defaults,_netdev  0  0


For NFS and CIFS mounts, _netdev should be considered mandatory rather than optional. Pair it with nofail on mounts where the remote server may not always be reachable:


Code:
//192.168.1.50/share  /mnt/samba  cifs  credentials=/etc/samba/creds,_netdev,nofail  0  0


x-systemd.automount


This option hands mount management over to systemd's automount units. Rather than mounting the filesystem at boot, systemd creates an automount point. The filesystem is mounted on first access and, optionally, unmounted after a period of inactivity.


Code:
UUID=a1b2c3d4-e5f6-7890-abcd-ef1234567890  /mnt/archive  ext4  defaults,x-systemd.automount  0  2


This is a step beyond noauto. With noauto, you manually decide when to mount. With x-systemd.automount, the filesystem appears to always be available — accessing the mountpoint triggers the mount transparently. This works well for slow or occasionally unavailable resources like NFS shares or large archive volumes where you want seamless access without the overhead of keeping them mounted continuously.


You can also control idle unmount behavior:


Code:
UUID=...  /mnt/archive  ext4  defaults,x-systemd.automount,x-systemd.idle-timeout=10min  0  2


Be aware that x-systemd.automount is systemd-specific. It will not behave as expected on systems using a different init system.


That wraps up Part 1. Part 2 will cover the dump and pass fields, handling slow-spinning or late-enumerating devices with systemd timeouts, and a complete annotated fstab example pulling everything together.
 


Understanding /etc/fstab: Mount Options and Boot Behavior — Part 2


Part 1 covered the options field — defaults, auto/noauto, nofail, _netdev, and x-systemd.automount. Part 2 covers the two numeric fields that close every fstab entry, the real-world problem of devices that enumerate slowly at boot, and a complete example bringing everything together.


When nofail Is Not Enough: Slow Devices and Boot Timeouts


nofail handles missing devices gracefully, but there is a related problem it does not solve on its own: devices that are present but not yet ready when systemd attempts the mount.


Slow-spinning hard drives, USB-attached storage, hardware RAID arrays, and some SAN or iSCSI configurations can take several seconds to fully enumerate and become accessible after power-on. If systemd attempts the mount before the device is ready, the mount fails. Without nofail the system drops to emergency mode. With nofail alone, the mount is skipped and the filesystem is never mounted — which may not be acceptable if you actually need it.


The solution is to give systemd a device timeout: an amount of time it will wait for the device to appear before deciding it is not coming.


Code:
UUID=a1b2c3d4-e5f6-7890-abcd-ef1234567890  /mnt/slowdisk  ext4  defaults,nofail,x-systemd.device-timeout=30  0  2


The x-systemd.device-timeout option accepts a value in seconds, or a time string like 30s, 1min, and so on. In the example above, systemd will wait up to 30 seconds for the device to appear before giving up. If the device enumerates within that window — which slow drives almost always will — the mount proceeds normally. If it does not appear within the timeout, nofail ensures the boot continues anyway rather than dropping to maintenance mode.


This combination — nofail with x-systemd.device-timeout — is particularly valuable on systems with:


— Large spinning disk arrays that take time to spin up— USB drives that are expected to be present but may lag behind the boot sequence— Hardware RAID controllers that perform initialization before presenting volumes to the OS— Any device where you have seen "gave up waiting for device" in your boot logs


You can verify what systemd is doing with device mounts by checking:


Code:
systemctl list-units --type=mount


For more detail on a specific mount unit:


Code:
systemctl status mnt-slowdisk.mount


If a mount is failing at boot, journalctl will show you exactly what happened and when:


Code:
journalctl -b -u mnt-slowdisk.mount


The Dump Field (Column 5)


The fifth field controls behavior for the dump utility, a backup tool that has been part of Unix systems since the 1970s. A value of 1 marks the filesystem for inclusion in dump backups. A value of 0 excludes it.


In practice, virtually nobody uses dump anymore. Modern backup solutions — rsync, Bacula, Amanda, Restic, Duplicati, and many others — do not consult fstab at all. The dump field is a legacy artifact that survives because it costs nothing to include and removing it would require explaining why to everyone who notices.


The correct value for the dump field on any modern system is almost always 0. You will rarely if ever encounter a situation where setting it to 1 changes anything meaningful.


The Pass Field (Column 6)


The sixth field controls the order in which fsck checks filesystems at boot. It accepts one of three values: 0, 1, or 2.


A value of 0 disables fsck for that filesystem entirely. It will not be checked at boot regardless of its state.


A value of 1 marks the filesystem for the first pass. This should be used only for the root filesystem. fsck checks pass-1 filesystems before any others, ensuring the root partition is clean before dependent mounts proceed.


A value of 2 marks the filesystem for the second pass. All non-root local filesystems that should be checked receive a 2. Multiple filesystems with a value of 2 may be checked in parallel on systems that support it, which can meaningfully reduce boot time on machines with many disks.


Code:
UUID=...  /           ext4  defaults                0  1UUID=...  /mnt/data   ext4  defaults                0  2UUID=...  /mnt/backup ext4  defaults,noauto,nofail  0  0


Network filesystems, tmpfs, and any filesystem type where fsck is not applicable should always use 0. NFS and CIFS mounts in particular must have 0 in the pass field — fsck cannot check a remote filesystem and attempting it will produce errors.


For SSDs with journaling filesystems like ext4 or xfs, fsck is rarely needed in practice, but there is no harm in leaving pass set to 2. Some administrators set all non-root filesystems to 0 on all-SSD systems as a minor boot optimization. Either approach is defensible.


A Complete Example


A well-constructed fstab for a workstation with a root partition, a secondary data disk, a slow-enumerating backup array, and an NFS share might look like this:


Code:
UUID=11111111-1111-1111-1111-111111111111  /            ext4  defaults                                     0  1UUID=22222222-2222-2222-2222-222222222222  /mnt/data    ext4  defaults                                     0  2UUID=33333333-3333-3333-3333-333333333333  /mnt/backup  ext4  defaults,nofail,x-systemd.device-timeout=30  0  2UUID=44444444-4444-4444-4444-444444444444  /mnt/archive ext4  defaults,noauto,nofail                       0  0192.168.1.50:/export/media  /mnt/media   nfs   defaults,_netdev,nofail                                     0  0


Each entry reflects a deliberate choice. The root partition is checked first. The data disk is checked in parallel with anything else at pass 2. The backup array gets extra time to enumerate but does not stall the boot if it never appears. The archive disk stays unmounted until requested. The NFS share waits for the network and fails gracefully if the server is unreachable.


Closing Thoughts


fstab is one of those files that most administrators interact with infrequently enough that its options never get the attention they deserve. The result is systems full of entries where everything is set to defaults and 0 0 because that is what the previous administrator did, and the one before them. Understanding what noauto, nofail, _netdev, x-systemd.device-timeout, and the pass field actually do means you can make intentional choices — and avoid the kind of boot-time emergencies that come from a missing or slow disk dropping a server into maintenance mode at 2 AM.
 
Thanks for this explanation. I've used Linux for decades and almost never had to mess with fstab directly, but this opens up some interesting possibilities.
 


Follow Linux.org

Members online

No members online now.

Top