Chapter 9: Services and the boot process

Recovering a system that will not boot normally

Sooner or later a machine will not boot, or nobody remembers the root password. RHEL gives an administrator with console access a way in: you can interrupt the boot, change the kernel arguments, and repair the system from outside. This lesson explains the two most common repairs: resetting a lost root password, and fixing a bad /etc/fstab.

Rescue and emergency modes

If systemd cannot reach the default target, it drops to a shell on the console. You can also ask for one deliberately by adding a kernel argument in the GRUB menu (press e, add it to the linux line, boot with Ctrl+X):

ArgumentYou getUse it when
systemd.unit=rescue.targetSingle-user shell, basic system and file systems mounted, no networkA service or configuration problem; the base system is fine
systemd.unit=emergency.targetThe most minimal shell; root file system mounted read-only, nothing elseEven rescue mode fails, for example a broken /etc/fstab
rd.breakA shell inside the early boot (initramfs), before the real root is in useYou lost the root password

Rescue and emergency modes ask for the root password. rd.break does not, which is exactly why it can be used to reset it.

Reset a lost root password

Reset a lost root password: Step through the standard recovery on a machine you have console access to.

Replay the commands of steps 4 to 7 here to see what they print. This terminal cannot boot your lab; it only shows the dialogue.

A few details worth understanding:

A bad /etc/fstab

/etc/fstab lists the file systems that are mounted at boot. A line for a device that does not exist makes systemd wait for it, time out, and drop you into emergency mode, with a message like "You are in emergency mode" and a request for the root password.

To recover: enter the root password, make the root file system writable, fix the line, and reboot.

[root@servera ~]# mount -o remount,rw /
[root@servera ~]# vim /etc/fstab
[root@servera ~]# systemctl daemon-reload
[root@servera ~]# mount -a
[root@servera ~]# systemctl reboot

Better still, avoid the problem. Before you reboot after editing /etc/fstab:

[root@servera ~]# findmnt --verify
/data
   [E] unreachable on boot required target: No such file or directory
   [W] unreachable source: /dev/sdb1: No such file or directory
...
[root@servera ~]# mount -a
mount: /data: mount point does not exist.

Check your understanding