CentOS 7 in detail how to reset and restore GRUB menu after forget the root password

Introduction GRUB menu

For the Linuxoperating system, the GRUB( GRand Unified Bootloaderunified boot loader) is the most widely used multi-system boot program. After the transfer system control to GRUB, the boot menu will be displayed to the user to select and load depending on the option (or default value) Linuxkernel file, then the system control to the kernel. It should be noted that the CentOS 7use of the GRUB2boot loader.

GRUB menu recovery method

GRUBMost Linuxoperating systems use the default boot program, you can choose to enter a different operating system (if any) by way of the boot menu. When the configuration file /boot/grub2/grub.cfgis missing, or the key to a configuration error, or a boot loader in the MBR gets damaged, it may only start after the Linux host “grub>”prompt, unable to complete the boot process further. Here we have to practice to simulate the GRUB menu by damage and repair process. (Practice complete virtual machine in VMware 15)

1, open the VMware 15virtual machine, start Linuxthe system, open a terminal, the command to delete GRUBthe menu configuration file ( /boot/grub2/grub.cfg), analog GRUBmenu damaged, restart the Linuxsystem to see if the system can start.

[root@localhost ~]# rm -rf /boot/grub2/grub.cfg    //删除grub配置文件,模拟grub菜单损坏
[root@localhost ~]# init 6                         //重启Linux系统

CentOS 7 in detail how to reset and restore GRUB menu after forget the root password

2, let's fix GRUBmenu, the system to boot, repair GRUB menu can be entered manually grubconfigure the File menu to complete the repair, grubmany menu configuration file, manual input is very convenient, generally use this method we will not go, Another way is to use the CentOS 7image files (CD-ROM) to boot into rescue mode, enter the command bash environment, reload the configuration file, the grubmenu configuration file recovery.

  • First, the image file into CentOS 7 VMware 15 virtual drive, the drive connection and, then, restart the system, press the ESC key to restart the reading of the interface into boot mode select boot from the CD into the installation guide interface.

CentOS 7 in detail how to reset and restore GRUB menu after forget the root passwordCentOS 7 in detail how to reset and restore GRUB menu after forget the root passwordCentOS 7 in detail how to reset and restore GRUB menu after forget the root password

  • Installed in the boot image file selection screen Troubleshootinginto the emergency mode, and then selecting Rescue a CentOS systemto enter the command mode of the mirror, this time the system will automatically load, loading is completed after the selection input 1selecting Continueloaded into the system base image mode, the Enter key to enter shellthe environment.

CentOS 7 in detail how to reset and restore GRUB menu after forget the root passwordCentOS 7 in detail how to reset and restore GRUB menu after forget the root passwordCentOS 7 in detail how to reset and restore GRUB menu after forget the root password

  • In the shellinput mode command chroot /mnt/sysimage/to load system image, this time will enter the bash environment, bashenter the command environment grub2-install /dev/sda/to rebuild sdathe disk, and then continue to enter the command grub2-mkconfig -o /boot/grub2/grub.cfgto rebuild grub2the configuration file, enter the exitcommand to exit bashthe environment.

CentOS 7 in detail how to reset and restore GRUB menu after forget the root password

  • This time we enter the command reboot reboot the system to see whether the subject can boot normally.

CentOS 7 in detail how to reset and restore GRUB menu after forget the root password

CentOS 7 in detail how to reset and restore GRUB menu after forget the root password

After forget the root password reset method

In daily production environment, it is possible to forget rootthe user password, or the transfer of work in the future and transfer rootgenerated user passwords and other circumstances, this time we need to reset rootyour password.

In CentOS 7the password reset method is relatively simple, we need to use the same CentOS 7image file, and repair of the above grubmenu is similar to the way into emergency mode through the mirror installation guide, enter the command, the command mode input selection into the shell environment, the above has been explained how into the shellenvironment here is not in the repeat.

1, the shellinput mode command to chroot /mnt/sysimage/load the system image, this time will enter the bashenvironment, bashdirectly enter the command environment passwd rootcommand, and then enter the new password to change the rootpassword.

CentOS 7 in detail how to reset and restore GRUB menu after forget the root password

2, enter the command exitto exit the bashenvironment, and then enter the command rebootto restart the system, and then select roota user, enter the new password to see if it can enter the rootuser interface.

CentOS 7 in detail how to reset and restore GRUB menu after forget the root password

CentOS 7 in detail how to reset and restore GRUB menu after forget the root passwordCentOS 7 in detail how to reset and restore GRUB menu after forget the root passwordCentOS 7 in detail how to reset and restore GRUB menu after forget the root password

Through the above practice successfully CentOS 7repair the image file grubmenu and rootreset user passwords. I hope to be helpful! ! !

to add on

CentOS 7System image file: https://pan.baidu.com/s/189yvb_WAYi8vrIhhxBwoXA extraction code:6crs

Guess you like

Origin blog.51cto.com/14473285/2432770