GRUB2: boot to a second (another) hard disk

dual-bootgrub2

I have researched for this question, but have not been able to find a clear answer… or even a clear question. So I will use a simple example.

My computer have **two hard disks:
**

  • Hard Disk 1: Ubuntu Linux with GRUB2 on MBR.
  • Hard Disk 2: Any other operating system (does it bother which one?) with some other MBR loader.

GRUB2 only boots to Ubuntu (on 1st hard disk, in my example).
Issuing update-grub does not detect the operating system on the 2nd hard disk, but I know there is one.
If I enter the BIOS on boot time and change boot order to Hard Disk 2, the second operating system boots OK.

How can I add an entry to GRUB2 that boots to the second hard disk?

(The fact is: I think this question can be asked without specifying which one is the operating system in the 2nd hard disk. Or not?)

Adding upon request output of os-prober for a sample machine with this configuration:

luis@threepwood:~$ sudo os-prober
/dev/sdb1:Windows 7 (loader):Windows:chain
/dev/sdb7:Ubuntu 14.04.3 LTS (14.04):Ubuntu:linux

In this particular example (I changed boot order at BIOS) case:

  • sdb is HDD-1.
  • sda is HDD-2.

Best Answer

I normally write grub.cfg manually and never use update-grub and have a so called master Grub2 bootloader where i choose from where to boot from, then i let each linux distro to install its own bootloader on its own root partition, so linux can edit its own bootloader without touching my master grub2 bootloader.

And for jumping to other disk MBR i have this kind of entries on grub.cfg for normal OS that do not need to see the disk as if it where the first disk:

menuentry "Boot from second disk" {
   chainloader (hd1)+1
}
menuentry "Boot from third disk" {
   chainloader (hd2)+1
}
menuentry "Boot from fourth disk" {
   chainloader (hd3)+1
}

So it just load the MBR on the other disk i want.

But for some tricky Linux (and also some Windows) that want to see the other disk as if it where the first one i also add some orders to grub menu entries, so it looks like this:

menuentry "Boot from second disk and see it as first disk" {
   set root=(hd1)
   drivemap -s hd0 hd1
   chainloader +1
}
menuentry "Boot from third disk and see it as first disk" {
   set root=(hd2)
   drivemap -s hd0 hd2
   chainloader +1
}
menuentry "Boot from fourth disk and see it as first disk" {
   set root=(hd3)
   drivemap -s hd0 hd3
   chainloader +1
}

All explained in detail:

  • (hd#) represents the disk, where # starts from zero

  • drivemap do the swap of drives, so any disk can be seen as first disk, or whatever number you want (it swaps the order on what are seen two disks)

  • chainloader (hd#)+1 jumps to MBR of the disk

  • chainloader +1 jumps to first sector of what is stored on (root)

  • set root=... sets what (root) have.

  • (root) is like a variable, can be used to type less

For full documentation on grub.cfg file you can see official web page:

https://www.gnu.org/software/grub/manual/grub/grub.html

Related Question