Location>code7788 >text

redhat8 rhel8 boot grub corruption repair

Popularity:725 ℃/2024-08-20 15:42:05

Environment: redhat8.4 RHEL8.4

Server: Huawei G560

Problem description: Adjusted the /etc/default/grub file to regenerate /boot/grub2/ causing the machine to fail to boot and go directly into rescue mode

Solution:

Launch to the following screen

 

Select c to enter the grub command interface

You can use the ls command to go through the drives

 

  • (hd0) is the first hard disk.
  • (hd0,msdos1) is the first partition on the first hard disk.
  • (hd0,msdos2) is the second partition on the first hard disk.
  • (hd0,msdos3) is the third partition on the first hard disk.

  

In general, for LVM structure disks, the correspondence is as follows, which is also the correspondence of my system (this structure needs to be carefully differentiated according to your own system)

  • (hd0,msdos1) is the first partition on the first hard disk, which corresponds to /dev/sda1, the file system /boot in the system, and the partition where the boot files are stored Corresponds to the system deployed and booted in the traditional way.
  • (hd0,msdos2) is the second partition on the first hard disk, which corresponds to /dev/sda2, that is, the file system /boot/efi in the system, which corresponds to the system deployed and booted by UEFI method.
  • (hd0,msdos3) is the third partition on the first hard disk, which corresponds to /dev/sda3, the partition where the other filesystems in the system, the root VG, are located

The above correspondences can also be made with similar systems.

The contents of the disk can be viewed in detail with the command

Now that that's clear, let's start

Manual boot

First let the bootloader find the boot file

grub> set root=(hd0,msdos1)

Then load the kernel version to the root partition, my root partition is in sda3

  • For direct disk installations the command is as follows

grub> linux16 /vmlinuz-4.18.0-305.el8.x86_64 ro root=/dev/sda2

  • For LVM structured systems, the commands are as follows

 grub>  linux16 /vmlinuz-4.18.0-305.el8.x86_64 ro root=/dev/mapper/vgrhel-lvroot

Finally, load the system kernel image

grub>  initrd16 /initramfs-4.18.0-305.el8.x86_64.img

grub>  boot

The above manual boot does not allow the system to boot properly the next time.

 

 Configure automatic startup:

As a conclusion, never edit /etc/default/grub or /etc/sysconfig/grub by hand.

Since I manually edited /etc/default/grub, perform the following steps

  • Deleting configuration files

       # rm /etc/default/grub

  • Reinstall the package

       # yum reinstall grub2-tools

  • redevelopment file to make the changes take effect

        # grub2-mkconfig -o /boot/grub2/

  • Reinstall GRUB in the/boot/ Recovering GRUB on a Partition

       # grub2-install /dev/sda

  • validate (a theory)

       # reboot

The above steps are based on BIOS installation, for UEFI installation please refer to /zh_hans/documentation/red_hat_enterprise_linux/8/html/managing_monitoring_and_updating_the_kernel/ proc_resetting-grub_assembly_reinstalling-grub

 

Related content

To view and configure grub use the following commands:

# grubby

 

 

 

There are other cases of processing steps, please refer to: /Howei__/article/details/104537757 This article for the actual operation after the record