是否可以在不重新启动的情况下验证 grub 安装?

mob*_*ius 34 grub2

我已经被这个咬了很多次了,今天openssl在我的服务器 grub 更新后抱怨我应该重新安装它,因为“以前安装的硬盘不存在”。

我有一个带有以下设置的raid 1安装(根据bootinfoscript):

> ============================= Boot Info Summary: ===============================
> 
>  => Grub2 (v1.99) is installed in the MBR of /dev/sda and looks at
> sector 1 of the same hard drive for core.img. core.img is at this location and looks
>     for (mduuid/d2a04f98760e2b3cc23ba87845667605)/grub on this drive.  
>
> => Grub2 (v1.99) is installed in the MBR of /dev/sdb and looks at sector 1 of
>     the same hard drive for core.img. core.img is at this location and looks
>     for (mduuid/d2a04f98760e2b3cc23ba87845667605)/grub on this drive.

My mount points are:

> /dev/md2 on / type ext4 (rw) 

> /dev/md1 on /boot type ext3 (rw)

And mduuid seems to match the ones bootinfoscript mentions:

> ls -l /dev/disk/by-id/md-uuid-*
>
> lrwxrwxrwx 1 root root 9 Mar 19 11:37 /dev/disk/by-id/md-uuid-38048286:e3004e47:510ca3e1:2bae3f2e -> ../../md2 
>
> lrwxrwxrwx 1 root root 9 Mar 19 11:37 /dev/disk/by-id/md-uuid-d2a04f98:760e2b3c:c23ba878:45667605 -> ../../md1 
>
> lrwxrwxrwx 1 root root 9 Mar 19 11:37 /dev/disk/by-id/md-uuid-e099b695:0143bb58:e4ef7645:0f22ce0b -> ../../md0
Run Code Online (Sandbox Code Playgroud)

运行 grub-install 有效,但我想确保在重新启动 grub 后实际上会正确启动我的分区。

我该如何验证?

May*_*hux 27

我认为您不能在尝试之前检查这是否有效,而是可以立即预览您的 GRUB,这样您就可以确保在 GRUB 中正确加载了您的新配置。

这可以使用名为grub-emu.

man grub-emu

NAME
       grub-emu - GRUB emulator

SYNOPSIS
       grub-emu [OPTION]...

DESCRIPTION
       GRUB emulator.

       -r, --root-device=DEV
              use DEV as the root device [default=guessed]

       -m, --device-map=FILE
              use FILE as the device map [default=/boot/grub/device.map]

       -d, --directory=DIR
              use GRUB files in the directory DIR [default=/boot/grub]

       -v, --verbose
              print verbose messages
Run Code Online (Sandbox Code Playgroud)

grub-emu使用命令行轻松安装:

sudo apt-get install grub-emu
Run Code Online (Sandbox Code Playgroud)

要运行它,只需使用终端运行此命令:

grub-emu
Run Code Online (Sandbox Code Playgroud)

  • @MichaelScheper 这修复了交互性 https://serverfault.com/a/847429/163750 :)。基本上,`xterm -e grub-emu` 并将焦点保持在 xterm 而不是 grub-emu 窗口! (3认同)
  • 这是对 grub2 安装的可靠测试吗?此外,键盘输入似乎不适用于出现的菜单;有启用它的技巧吗? (2认同)
  • 我无法关闭 `grub-emu`,唯一的方法是停止它是 `pkill -SIGKILL -fe grub-emu`,键盘输入也不起作用 (2认同)
  • 您必须将焦点设置到启动模拟器的终端上才能进行输入!模拟器自身的窗口根本不会对任何输入做出反应。 (2认同)

jkt*_*123 5

此答案用于file -s /dev/sda查看 GRUB MBR 是否已成功安装。在那之后,您绝对可以仔细检查中的值/boot/grub/grub.cfg以确保 UUID 与 中的值匹配/dev/disk/by-uuid,并确保/boot/grub/device.map. 如果该文件有误,您将在 grub.cfg 中遇到 (hdX) 规范问题。

如果您update-grub在替换驱动器上安装 grub 后使用,则不需要手动管理这些文件。根据我的经验,最大的问题是没有更新 GRUB 配置,没有在所有驱动器上安装 GRUB,或者分区不当导致您无法在不使用 --force 的情况下安装 GRUB。

  • 该答案仅对 grub1 使用 `file -s`,对于 grub 2,还有第二个答案建议`dd bs=512 count=1 if=/dev/sda 2>/dev/null | 字符串|grep GRUB` (2认同)