So you end up here because you have lost your root password. On Red Hat Enterprise Linux 8, it is possible to have the scripts that run from the initramfs pause at certain points, provide a root shell, and then continue when that shell exits. This is mostly meant for debugging, but you can also use this method to reset a lost root password. To access that root shell, follow these steps:
- Reboot your server.
- Interrupt the boot loader countdown by pressing any key, except Enter.
- Move the cursor to the kernel entry to boot.
- Press e to edit the selected entry.
- Move the cursor to the kernel command line (the line that starts with linux).
- Append rd.break. With that option, the system breaks just before the system hands control from the initramfs to the actual system.
- Press Ctrl+x to boot with the changes.
- To reset the root password from this point, use the following procedure:
- Remount /sysroot as read/write.
switch_root:/# mount -o remount,rw /sysroot
- Switch into a chroot jail, where /sysroot is treated as the root of the file-system tree.
switch_root:/# chroot /sysroot
- Set a new root password.
sh-4.4# passwd root
- Ensure that all unlabeled files, including /etc/shadow at this point, get relabeled during boot.
sh-4.4# touch /.autorelabel
- Type exit twice. The first command exits the chroot jail, and the second command exits the initramfs debug shell.
- At this point, the system continues booting, performs a full SELinux relabel, and then reboots again.