如何從 GRUB 丟失其條目並在啟動時僅遇到“grub> _”的情況中恢復?

如何從 GRUB 丟失其條目並在啟動時僅遇到“grub> _”的情況中恢復?

我相當成功地執行了從 CentOS 7 到 AlmaLinux 8 的系統升級(如前所述這裡)。在此過程中發生了一些奇怪的事情,GRUB 完全丟失了其引導條目,而我在重建它們/它方面的有限努力(我實際上只需要 AlmaLinux 8 內核條目,並且到目前為止只有一個vmlinuz+映像)已經失敗(特別是因為initrd自從幾十年前使用 Gentoo 以來,我就不再需要直接擺弄 GRUB)。

目前,為了讓伺服器啟動,我基本上必須進入 Linode 伺服器上的 LISH(特別是 Glish)控制台,這就是我重新啟動時得到的結果:

英語:

SeaBIOS (version rel-1.12.1-0.ga5ca58e9aef-prebuilt.qemu.org)

iPXE (http://ipxe.org) 00:04.0 C980 PCI2.10 PnP PMM+7FF90F20+7FEF0F20 C980


Booting from ROM...
Welcome to GRUB!

error: variable `prefix' isn't set.

然後在 Lish 和 Weblish 中:

                             GNU GRUB  version 2.04
   Minimal BASH-like line editing is supported. For the first word, TAB
   lists possible command completions. Anywhere else TAB lists possible
   device or file completions.


grub> _

然後,我必須輸入以下內容,我自己拼命拼湊這些內容,以ls (hd0)/boot/使系統啟動到非單一使用者模式,以使其啟動:

set root=(hd0)
linux /boot/vmlinuz-4.18.0-372.9.1.el8.x86_64 root=/dev/sda console=ttyS0,19200n8
initrd /boot/initramfs-4.18.0-372.9.1.el8.x86_64.img
boot

(經過調查和討論,後來發現了應該發布的一組可能經過改進的引導參數:

set root=(hd0)
linux /boot/vmlinuz-4.18.0-372.9.1.el8.x86_64 root=/dev/sda ro crashkernel=auto rhgb console=ttyS0,19200n8 net.ifnames=0
initrd /boot/initramfs-4.18.0-372.9.1.el8.x86_64.img
boot

我想我可以grub2-mkconfig通過以下命令簡單地修復此問題,但正如您所看到的,它根本沒有找到任何條目:

$ grub2-mkconfig --output /boot/grub2/grub.cfg
Generating grub configuration file ...
done

當查看生成的b2/grub.cfg :: 10_linux部分時,我們看到:

### BEGIN /etc/grub.d/10_linux ###
insmod ext2
set root='hd1'
if [ x$feature_platform_search_hint = xy ]; then
  search --no-floppy --fs-uuid --set=root --hint-bios=hd0 --hint-efi=hd0 --hint-baremetal=ahci0 --hint='hd1'  06e9a827-47b4-43f9-8e01-91b3852f86a8
else
  search --no-floppy --fs-uuid --set=root 06e9a827-47b4-43f9-8e01-91b3852f86a8
fi
insmod ext2
set boot='hd1'
if [ x$feature_platform_search_hint = xy ]; then
  search --no-floppy --fs-uuid --set=boot --hint-bios=hd0 --hint-efi=hd0 --hint-baremetal=ahci0 --hint='hd1'  06e9a827-47b4-43f9-8e01-91b3852f86a8
else
  search --no-floppy --fs-uuid --set=boot 06e9a827-47b4-43f9-8e01-91b3852f86a8
fi

# This section was generated by a script. Do not modify the generated file - all changes
# will be lost the next time file is regenerated. Instead edit the BootLoaderSpec files.
#
# The blscfg command parses the BootLoaderSpec files stored in /boot/loader/entries and
# populates the boot menu. Please refer to the Boot Loader Specification documentation
# for the files format: https://www.freedesktop.org/wiki/Specifications/BootLoaderSpec/.

# The kernelopts variable should be defined in the grubenv file. But to ensure that menu
# entries populated from BootLoaderSpec files that use this variable work correctly even
# without a grubenv file, define a fallback kernelopts variable if this has not been set.
#
# The kernelopts variable in the grubenv file can be modified using the grubby tool or by
# executing the grub2-mkconfig tool. For the latter, the values of the GRUB_CMDLINE_LINUX
# and GRUB_CMDLINE_LINUX_DEFAULT options from /etc/default/grub file are used to set both
# the kernelopts variable in the grubenv file and the fallback kernelopts variable.
if [ -z "${kernelopts}" ]; then
  set kernelopts="root=/dev/sda ro crashkernel=auto rhgb console=ttyS0,19200n8 net.ifnames=0 "
fi

insmod blscfg
blscfg
### END /etc/grub.d/10_linux ###

確實/boot/loader/entries/還有一個文件似乎與應該透過 BLS 啟動的文件相對應:

title AlmaLinux (4.18.0-372.9.1.el8.x86_64) 8.6 (Sky Tiger)
version 4.18.0-372.9.1.el8.x86_64
linux /boot/vmlinuz-4.18.0-372.9.1.el8.x86_64
initrd /boot/initramfs-4.18.0-372.9.1.el8.x86_64.img $tuned_initrd
options $kernelopts $tuned_params
id almalinux-20220510130458-4.18.0-372.9.1.el8.x86_64
grub_users $grub_users
grub_arg --unrestricted
grub_class kernel

至於grubenv

$ grub2-editenv list
saved_entry=4f09fa5fdd3642fa85221d7c11370603-4.18.0-372.9.1.el8.x86_64
kernelopts=root=/dev/sda ro crashkernel=auto rhgb console=ttyS0,19200n8 net.ifnames=0
boot_indeterminate=1

啟動期間的 GRUB 條目似乎應包含:

linux /boot/vmlinuz-4.18.0-372.9.1.el8.x86_64 root=/dev/sda ro crashkernel=auto rhgb console=ttyS0,19200n8 net.ifnames=0

然而它並沒有......而且我實際上還沒有手動修改任何東西,所以我不知道 GRUB 在哪裡/如何變得困惑。

作為健全性檢查,我驗證了軟體包是否按預期安裝:

$ dnf install kernel grub2
Last metadata expiration check: 2:31:00 ago on Fri Jun 17 13:43:41 2022.
Package kernel-4.18.0-372.9.1.el8.x86_64 is already installed.
Package grub2-pc-1:2.02-123.el8.alma.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!

最終,GRUB 似乎找不到或無法解析grub.cfg...

我認為可能存在涉及 EFI 的某種更改,因為似乎更新正在發生,/boot/grub2/grub.cfg並且我注意到已經生成了一個新的空資料夾/boot/efi/EFI/almalinux/,因此我grub.cfg也嘗試在那裡生成:

$ grub2-mkconfig --output /boot/efi/EFI/almalinux/grub.cfg
Generating grub configuration file ...
done

但正如您所看到的,生成期間和生成過程中仍然沒有任何條目,並且當我重新啟動時,也沒有執行 BLS 自動生成/使用(因為我認為我知道這可能會發生)。

以下是各種可能相關的資料夾的內容/boot/https://gist.github.com/ylluminate/d469ce8ace202a57f67f5aed255154cd

我該怎麼做才能讓 GRUB 建置和/或解析並再次使用正確的配置?

答案1

事實證明,在 Linode 伺服器上下文中解決此問題的關鍵是停用GRUB_ENABLE_BLSCFG並重新運行grub2-mkconfig,例如:

$ nano /etc/default/grub
### set: GRUB_ENABLE_BLSCFG=false
$ grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.18.0-372.9.1.el8.x86_64
Found initrd image: /boot/initramfs-4.18.0-372.9.1.el8.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-4f09fa5fdd3642fa85221d7c11370603
Found initrd image: /boot/initramfs-0-rescue-4f09fa5fdd3642fa85221d7c11370603.img
done

相關內容