41

I've been bitten by this so many times, and today after the openssl updates in my server grub complained that I should install it again since the "hard disks that it was previously installed do not exist".

I have a raid 1 installation with the following setup (according to 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

Running grub-install works, but I want to make sure that after rebooting grub will actually correctly boot up my partitions.

How can I verify it?

Maythux
  • 84,289
mobius
  • 471
  • 1
  • 4
  • 6
  • 2
    I do not use nor really know RAID, but you install grub to the root of the RAID not to the MBR of a drive. If you run Boot-Repair you then might get a message like this. No boot loader is installed in the MBR of /dev/mapper/isw_cdjacjeebj_VOLUME_0. Where the mapper is your RAID volume. – oldfred Apr 11 '14 at 04:07
  • related: https://serverfault.com/questions/61400/how-do-i-tell-if-grub-is-installed-on-a-device – Ciro Santilli OurBigBook.com Jan 15 '19 at 23:38

2 Answers2

32

I don't think you can just check whether this will works or not before trying to do it, but instead you can get a preview of your GRUB instantly so you can be sure that your new configuration is loaded correctly in GRUB.

This could be achieved using a tool called 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

Easily install grub-emu using command line:

sudo apt-get install grub-emu

To run it just use terminal to run this command:

grub-emu
Maythux
  • 84,289
  • 3
    Is this a reliable test for grub2 installations? Also, keyboard input doesn't seem to work for the menu that appears; is there a trick for enabling it? – Michael Scheper Apr 26 '19 at 21:35
  • 4
    I cant close grub-emu, only way to stop it is pkill -SIGKILL -fe grub-emu, keyboard input not working either – Aquarius Power May 02 '19 at 16:08
  • 4
    @MichaelScheper this fixes the interactiveness https://serverfault.com/a/847429/163750 :). Basically, xterm -e grub-emu and keep the focus on xterm not the grub-emu window! – Aquarius Power May 02 '19 at 16:17
  • @AquariusPower press c in boot menu, then type exit – Tschallacka Jan 24 '20 at 14:17
  • 1
    @Tschallacka for me that also does not work, emulator does not react on any inputs at all. – Marvin Emil Brach Oct 04 '20 at 12:07
  • 2
    You have to set focus to the termial in which you started the emulator to be able to do inputs! The window of the emulator self will not react to any inputs at all. – Marvin Emil Brach Oct 04 '20 at 12:36
  • 1
    to close grub-emu type c and then halt – MaxV Mar 19 '21 at 20:52
  • 1
    in my case it shows menu entries, but after selecting boot entry it says "error: sparse file not allowed", "can't find command linux", "can't find command initrd". but my os has booted successfully, so it looks like false negative. – quant2016 Feb 05 '23 at 10:36
6

This answer uses file -s /dev/sda to see if the GRUB MBR has been successfully installed. Past that, you could definitely double-check the values in /boot/grub/grub.cfg to make sure the UUIDs match up with the values in /dev/disk/by-uuid, and make sure that everything looks right in /boot/grub/device.map. If that file is wrong you'll have trouble with (hdX) specifications in grub.cfg.

Managing these files manually isn't necessary though if you're using update-grub after installing grub on replacement drives. The biggest gotchas in my experience have been not updating the GRUB configuration, not installing GRUB on all the drives, or improper partitioning that makes it so you can't install GRUB without using --force.

jkt123
  • 3,530
  • 22
  • 24