如何判断grub是否安装在设备上?

我怎样才能知道grub是否安装在磁盘上,如果它是什么设置(注意,它有什么根参数)

我需要检查软件RAID1arrays中的很多磁盘,以确保两个磁盘都安装了grub,每个磁盘上的grub具有适当的根值。

    更新:

    这个答案是从2009年开始的,适用于grub-legacy,而不是grub2。

    您可以使用file来识别MBR中的GRUB。 例如

     # file -s /dev/sda /dev/sda: x86 boot sector; GRand Unified Bootloader, stage1 version 0x3 , stage2 address 0x2000, stage2 segment 0x200; partition 1: ID=0xfd, starthead 1, startsector 63, 1044162 sectors; partition 2: ID=0x82, starthead 0, startsector 1044225, 1028160 sectors; partition 3: ID=0xfd, starthead 0, startsector 2072385, 1951447680 sectors, code offset 0x48 

    root= paramater不存储在MBR中,存储在GRUB的menu.lst文件中,该文件存储在文件系统中(通常位于根fs的/ boot / grub目录或/ boot文件系统的grub目录中 -但并不总是,它可能在任何地方)。

    你必须parsing上面的文件的输出,确定menu.lst文件在哪个磁盘/分区上,挂载它,读入并parsing它。 你还需要读取grub / default文件来确定哪个grub菜单项是默认的,因为这可能是你最感兴趣的root =参数的那个。

    替代方法

    file -s在Ubuntu Lucid中不适用于我,因为我的文件命令的魔法文件已经过期 。 如果你的魔法文件没有赶上GRUB的变化,另一种方法是使用dd命令来检查设备的前512个字节,如下所示:

     user@host:~$ sudo dd bs=512 count=1 if=/dev/sda 2>/dev/null | strings ZRr= `|f \|f1 GRUB Geom Hard Disk Read Error 

    这将通过strings命令发送dd命令的输出,从而删除不可打印的字符(将统计信息丢弃到/dev/null )。

    如果您看到GRUB在遇到故障时将显示的任何消息,那么您已经安装了grub。

    Hat提示在ubuntuforums.org上回答这个密码保护的post: http ://ubuntuforums.org/showthread.php?t=363372

    对于好奇,这是我从file -s得到的:

     user@host:~$ sudo file -s /dev/sda /dev/sda: x86 boot sector; partition 1: ID=0x83, active, starthead 32, startsector 20 48, 337211392 sectors; partition 2: ID=0x5, starthead 254, startsector 337215486, 1434214 6 sectors, code offset 0x63 

    那里没有关于GRUB的具体内容。

    您可以使用grub-emu来查看当机器下次重启时grub将显示的菜单。

     $ sudo apt-get install grub-emu $ sudo grub-emu 

    在我的台式机上,菜单显示如预期,但如果我真的假装启动一个内核,我得到了一个“没有这样的设备”的错误。 我认为这是预期的行为。

    在我的DigitalOcean VPS上,没有条目显示在grub菜单中,尽pipe服务器确实重启得很好。 (这是2013年VPS,所以你的里程可能会有所不同。)

    运行grub-emu时的一些注意事项:

    • 在X-windows中,如果你想和grub交互,你需要把你的键盘焦点 放在你运行grub-emu 的terminal上 ,而不是在popup的窗口上。
    • 您可以通过按c然后inputexit模拟器。
    • 退出后,terminal仿真程序可能处于不良状态(例如,Enter将不会显示在新行中)。 通过键入reset修复该问题 (别担心它不会重启你的机器,它只会清理你的terminal。)