Repair /etc/fstab Errors using Emergency Mode
In this step, you will learn how to diagnose and repair errors in the /etc/fstab file. This file is critical for the boot process as it tells the system which filesystems to mount and where. An incorrect entry in /etc/fstab can prevent the system from booting, forcing it into emergency mode.
Emergency mode provides the most minimal environment possible for system repair. Unlike rescue mode, it does not attempt to mount most filesystems or start many services. Crucially, the root filesystem (/) is mounted in read-only (ro) mode to prevent further damage.
While we cannot trigger a real boot failure in this lab, we can simulate the process of finding and fixing an /etc/fstab error.
First, let's intentionally add a faulty entry to /etc/fstab. We will use the echo command with sudo to append a line that references a non-existent device.
echo '/dev/nonexistent /data xfs defaults 0 0' | sudo tee -a /etc/fstab
Now, let's view the contents of /etc/fstab to confirm our bad line was added.
cat /etc/fstab
You should see the incorrect line at the end of the file.
#
## /etc/fstab
## Created by anaconda on <date>
#
## Accessible filesystems, by reference, are maintained under '/dev/disk/'.
## See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
#
## After editing this file, run 'systemctl daemon-reload' to update systemd
## units generated from this file.
#
/dev/vda4 / xfs defaults 0 0
/dev/vda2 /boot xfs defaults 0 0
/dev/vda1 /boot/efi vfat umask=0077,shortname=winnt 0 0
/dev/vda3 swap swap defaults 0 0
/dev/nonexistent /data xfs defaults 0 0
Next, we will simulate the diagnostic step. The mount -a command attempts to mount all filesystems listed in /etc/fstab that are not already mounted. Since our entry is invalid, this command will fail.
sudo mount -a
The command will produce an error, clearly indicating that the mount point /data does not exist. This is similar to the error you would see during a failed boot.
mount: /data: mount point does not exist.
Now, let's simulate the repair process. In a real emergency shell, the first step is to remount the root filesystem in read-write mode to allow for changes.
sudo mount -o remount,rw /
With the filesystem now writable, you can edit /etc/fstab to fix the error. Use the nano editor to open the file.
sudo nano /etc/fstab
Inside the nano editor, use the arrow keys to navigate to the faulty line (/dev/nonexistent /data xfs defaults 0 0) and delete it. You can delete the entire line by pressing Ctrl+k. Once the line is removed, save the file by pressing Ctrl+x, then y, and finally Enter.
To confirm the fix, run sudo mount -a again.
sudo mount -a
This time, the command should execute silently with no output, which indicates that all valid entries in /etc/fstab are correctly mounted. You have successfully repaired the file.