Before entering single-user mode to change the root password , the premise is that GRUB is not encrypted or the GRUB password is known.
If you cannot enter GRUB, use rescue mode.
- Shut down first
[root@localhost ~]# init 0
- Edit virtual machine settings
To tick "connect at startup"
Right click - power - enter BIOS on reboot (enter firmware when powered on)
Select "Boot"
Move "CD-ROM Driver" to the first line, then CD-ROM is the first to start
F10 save and exit
Enter the CD-ROM boot interface, select "Troubleshooting"
- Select the second item - Rescue a CentOS system (if you cannot enter GRUB, you can only use the CD-ROM drive to enter the "Rescue a CentOS system" interface)
- Select "1" to continue
chroot /mnt/sysimage/
- At this time, you can change the root password
- Modify the BIOS or edit the virtual machine settings, and then restart
Here choose the second
Click the small CD-ROM drive in the lower right corner of the virtual machine and select "Settings"
Uncheck it, do not connect CD-ROM at startup
- power - restart client