仅用于 UEFI 引导

要在 UEFI 引导中恢复 Grub,请执行以下命令:

# efibootmgr -v

之后运行:grub-install

# grub-install /dev/sda
如何在 CentOS/RHEL 5,6 中从损坏的引导分区恢复 GRUB

问题

系统卡在 grub> 提示符下,如下所示。

如何从这种情况中恢复过来。

解决方案

当我们遇到上述错误时,在大多数情况下,引导分区已损坏。

  1. 要解决问题,请从 grub 命令行执行:
grub> find /grub/stage1
find /grub/stage1
(hd0,0)

上面的命令将查找 stage1(stage1 放置在 MBR 中,稍后由 BIOS 读取)这将列出引导分区驻留的确切位置,在本例中为 hd0,0。

  1. 恢复 hd0,0 上的引导分区(第一个磁盘上的第一个分区),如上例中的 find 命令。
grub> root (hd0,0)
Filesystem type is ext4fs, partition type 0x83
  1. 然后在第一个磁盘 (hd0) 上设置 grub,如上例所示 boot stage1 位于 hd0 上。
grub>setup (hd0)
Checking if "/boot/grub/stage1" exists... yes
Checking if "/boot/grub/stage2" exists... yes
Checking if "/boot/grub/e2fs_stage1_5" exists... yes
Running "embed /boot/grub/e2fs_stage1_5 (hd0)"... 15 sectors are embedded.
succeeded
Running "install /boot/grub/stage1 d (hd0) (hd0)1+15 p (hd0,1)/boot/grub/stage
2 /boot/grub/menu.lst"... succeeded
Done.
  1. 命令成功后重启服务器。
grub> reboot

验证系统现在是否启动没有任何问题。

欢迎来到之路教程(on itroad-com)

进一步的故障排除

如果问题仍然存在并且系统再次在 grub 命令行上停止,请验证 grub.conf 是否存在并保持正确的值:

grub> find (hd0,0)/grub/grub.conf
find (hd0,0)/grub/grub.conf
(hd0,0)
grub> cat (hd0,0)/grub/grub.conf
cat (hd0,0)/grub/grub.conf
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/mapper/vg_lnxovmsan2076-lv_root
# initrd /initrd-[generic-]version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title Oracle Linux Server Unbreakable Enterprise Kernel (3.8.13-16.2.1.el6uek.x86_64)
root (hd0,0)
kernel /vmlinuz-3.8.13-16.2.1.el6uek.x86_64 ro root=/dev/mapper/vg_root-lv_root rd_NO_LUKS KEYBOARDTYPE=pc KEYTABLE=uk LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 rd_LVM_LV=vg_root/lv_root rd_LVM_LV=vg_root/lv_swap rd_NO_DM rhgb quiet crashkernel=256M@64M
initrd /initramfs-3.8.13-16.2.1.el6uek.x86_64.img
[Hit return to continue]

如果发现内核启动参数有问题,我们可以手动提供内核启动字符串:

grub> linux /boot/vmlinuz-3.8.13-16.2.1.el6uek.x86_64 ro root=/dev/mapper/vg_root-lv_root rd_NO_LUKS KEYBOARDTYPE=pc KEYTABLE=uk
grub> boot

如果这没有帮助,或者例如 grub.conf 文件丢失或者在 grub.conf 上运行 cat 时得到例如以下输出:

grub> cat (hd0,0)/grub/grub.conf
cat (hd0,0)/grub/grub.conf
???????????????????????????????????

有必要将系统引导至救援模式并使用“???”验证上面的输出发生了什么表明 root-fs 损坏。
如果即使在恢复 grub.conf 文件后 grub 仍然无法工作并且仍然在引导镜像周围出现 grub 错误,则需要重新安装系统。

日期:2020-09-17 00:13:47 来源:oir作者:oir