CentOS 8: reset a forgotten root password
Reset the root password from GRUB using rd.break and chroot /sysroot.
On a CentOS 8 machine whose root password is lost, you can reset it from the console at boot time, without external media. Reference: Tecmint, reset forgotten root password in CentOS 8.
Procedure
- Reboot the machine and, in the GRUB menu, press
eto edit the boot entry. - On the line starting with
linux, appendrd.breakat the end. - Boot with
Ctrl+X. The system stops in an emergency shell (initramfs). - Remount the filesystem read/write and change into it:
mount -o remount,rw /sysroot
chroot /sysroot
- Set the new password:
passwd root
- Request an SELinux relabel on the next boot, then reboot:
touch /.autorelabel
exit
exit
Notes
- The SELinux relabel (
/.autorelabel) is required for login to work; the first reboot can be slow. - This procedure requires console access to the machine; if GRUB is password-protected, it is not possible as is.