7

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.
  • Ubuntu has been known to have issues detecting RedHat-based installations/bootloader entries unless the latter are mounted at the time when update-grub is run. See the answer below from "Radek Radek" (phk) for more details. Though, it should be detected without the additional steps listed there after it's mounted. – ILMostro_7 Mar 17 '17 at 22:20
2

That is quite easy. Just follow the steps.

Example scenario:

  • /dev/sda1 – CentOS

  • /dev/sdb1 – Debian

Let's say that on CentOS drive has active MBR. So, we have access to CentOS system after booting; Debian has to be added.

Tasks under active OS (CentOS in our scenario):

  1. mount /dev/sdb1 /mnt/debian

  2. Cut the whole menuentry section of Debian from /mnt/debian/boot/grub{2}/grub.cfg, as below:

    menuentry 'Debian GNU/Linux' --class debian --class gnu-linux ... { ... }

  3. Now, create the file: touch /etc/grub.d/11_linux

  4. As this is script, remember to do: chmod +x /etc/grub.d/11_linux

  5. Add:

    #!/bin/sh
    echo "
    

    on the beginning of 11_linux and paste that section into it. Finished with " on the end. So, we should have:

    centos #~> cat /etc/grub.d/11_linux
    
    #!/bin/sh
    echo "menuentry 'Debian GNU/Linux' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-78026456-ebcc-4eed-b59d-a3f0bdff7353' {
        load_video
        insmod gzio
        if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
        insmod part_msdos
        insmod ext2
        set root='hd0,msdos1'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1  f2de4123-5a98-4568-99dd-e61940b99ab2
        else
          search --no-floppy --fs-uuid --set=root f2de4123-5a98-4568-99dd-e61940b99ab2
        fi
        echo    'Loading Linux 3.16.0-4-amd64 ...'
        linux   /vmlinuz-3.16.0-4-amd64 root=/dev/mapper/Thinkpad--vg-root ro  quiet
        echo    'Loading initial ramdisk ...'
        initrd  /initrd.img-3.16.0-4-amd64
    }"
    
  6. grub2-mkconfig -o /boot/grub{2}/grub.cfg

  7. Reboot.

Voila.

  • Seems actually just doing your step 6 seemed to solve the problem...os-prober finds the install and adds it to the list during the process, so doing all the steps will actually create duplicates. Although, that could be a difference between grub-mkconfig and grub2-mkconfig – redbmk May 31 '17 at 3:46
2

While I booted into GRUB from USB-Stick, I pressed c key for command-line mode, entered

rootnoverify (hd0)
chainloader +1
boot

et voilà, I got me GRUB too, but GRUB 2, trying again

set root=(hd0)
chainloader +1
boot

I get the same problem again, solved ;)

  • 3
    This answer is not very easy to understand. Could you edit it to clarify, please? – Robin Green Nov 1 '18 at 12:55
1

Hi I just had the same problem. I found that after I installed os-prober, grub-customizer was able to use os-prober to find the OS on the second HDD and add it to my boot menu. You might find this easier than editing the config files :)

0

I think you should add an entry for the second hdd , in grub configuration.

It doesn’t matter which OS that is.

I am using dual book with grub2 on windows HDD. It detects both windows and linux and offers me a menu to select an os to boot into.

For advance configuration , chainloading , and adding maunal entries to grub , follow this link:

https://help.ubuntu.com/community/Grub2/CustomMenus

  • I assume you are proposing something like # grub-install /dev/sdb. But that would replicate the same GRUB menu on HDD-2. Not a problem but... wouldn't that disable the already existing MBR on HDD-2 (lets suppose FreeBSD installed there: it records its own data on MBR)? – Sopalajo de Arrierez Jan 3 '16 at 4:18
  • 1
    what is the output of os-prober command? – Ijaz Ahmad Khan Jan 3 '16 at 4:39
  • The question is an hipothetycal case, but I have a machine with similar configuration, so I have edited the original question with that info. – Sopalajo de Arrierez Jan 3 '16 at 4:56
  • for adding the entry , read the syntax in the link provied – Ijaz Ahmad Khan Jan 3 '16 at 6:07
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.