Write an fstab entry that cannot stop the boot
Task
Break a machine's boot with a bad fstab entry, recover it from emergency mode, and then write the entry so that the same mistake cannot repeat. This is a failure people meet for the first time in production, at which point they are learning emergency mode under pressure.
Steps
- Create a loop-backed filesystem and mount it by hand at
/mnt/data. Note its UUID withblkid. - Add a correct fstab entry using the UUID, and prove it with
mount -afollowed byumountandmount -aagain. - Now break it: change one character of the UUID. Run
mount -aand read the error -- you have just caught the fault while still holding a shell. - Reboot with the broken entry and watch the machine drop to emergency mode. Log in at the console, note that the root filesystem is mounted read-only, and remount it read-write with
mount -o remount,rw /before you can edit anything. - Fix the UUID, verify with
mount -a, and reboot to confirm. - Break it once more, but this time add
nofailto the options. Reboot and confirm the machine comes up normally with the filesystem simply absent. - Add
_netdevto an entry for a network filesystem and explain what it changes about ordering.
Verify
findmnt --verify --verbose | tail -5
mount -a && echo "fstab parses and mounts cleanly"
grep -q 'nofail' /etc/fstab && echo "non-essential mounts are nofail"
systemctl list-units --type=mount --state=failed --no-pager | tail -2
findmnt --verify is the check worth adopting permanently: it validates every fstab line without mounting anything, and it reports problems that mount -a would only reveal by failing.
Notes
The habit this lab exists to build is one command long: run mount -a after every fstab edit, before rebooting. The fault then appears while you still have a working shell, rather than at the console of a machine that will not boot.