3

I have two encrypted Ubuntu installations (20.10) on two separate physical disks. I want to load the grub of the second installation from the first grub. Currently I only achieved loading a specific kernel of the second installation via a menu entry in my primary grub (added with grub customizer), using the following boot sequence:

recordfail
load_video
gfxmode $linux_gfx_mode
insmod gzio
if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
insmod part_gpt
insmod ext2
set root='hd2,gpt3'
if [ x$feature_platform_search_hint = xy ]; then
  search --no-floppy --fs-uuid --set=root --hint-bios=hd2,gpt3 --hint-efi=hd2,gpt3 --hint-baremetal=ahci2,gpt3  f54aac74-c88d-4963-a23f-84d5b27c2829
else
  search --no-floppy --fs-uuid --set=root f54aac74-c88d-4963-a23f-84d5b27c2829
fi
linux   /vmlinuz-5.8.0-33-generic root=/dev/mapper/vgubuntu-root ro  
initrd  /initrd.img-5.8.0-33-generic

Of course this will fail as soon as the kernel of second installation is updated as it points to a specific kernel. So I want to load the grub of the second installation from the first installation. I created the following image to illustrated the situation: desired grub setup

I tried two options (boot sequences):

chainloader (hd3,gpt3)/grub/x86_64-efi/core.efi

yields:

error: invalid signature

and (based on https://www.linuxquestions.org/questions/linux-software-2/grub2-chainloader-833236/)

search --fs-uuid --set f54aac74-c88d-4963-a23f-84d5b27c2829
multiboot /grub/x86_64-efi/core.img

yields:

error: file '/grub/x86_64-efi/core.img' not found

Thus both didn't work. So my question is how do I create a grub entry to load another grub instance?

Update: I tried the solution from @TSJNachos117 like this: I switched from grub-customizer to editing the following files directly: /etc/grub.d/40_custom_proxy was pointing to /etc/grub.d/proxifiedScripts/custom I added the following menu entry:

menuentry 'The Other Ubuntu' {
    insmod chain
    if [ x$feature_platform_search_hint = xy ]; then
      search --no-floppy --fs-uuid --set=root --hint-bios=hd2,gpt3 --hint-efi=hd2,gpt3 --hint-baremetal=ahci2,gpt3  f54aac74-c88d-4963-a23f-84d5b27c2829
    else
      search --no-floppy --fs-uuid --set=root f54aac74-c88d-4963-a23f-84d5b27c2829
    fi
    #set root=(hd2,3)
    configfile /boot/grub/grub.cfg
} 

When choosing this menu entry my screen goes black for about 10 seconds before showing the same grub menu again. Any hints what's wrong?

Here the output of lsblk -o name,type,uuid:

NAME                      TYPE  UUID
loop0                     loop  
loop1                     loop  
loop2                     loop  
loop3                     loop  
loop4                     loop  
loop5                     loop  
loop6                     loop  
loop7                     loop  
loop8                     loop  
loop9                     loop  
loop10                    loop  
sda                       disk  
└─sda1                    part  d8c4609f-a602-44e8-b8e5-d88b3ab664c2
  └─additional_disk_crypt crypt d07398f4-5f04-41bc-a31a-e44c112e3ae3
sdb                       disk  
├─sdb1                    part  
├─sdb2                    part  DA91-B238
├─sdb3                    part  9e57c5ea-219b-4b3a-8759-b98eb7d34c93
└─sdb4                    part  8f45cd57-43c9-413f-b3c5-88f4f943554a
  └─sda4_crypt            crypt Qb93l3-3kQ4-cL0y-beud-DjZ0-RXef-MosuKX
    ├─vgubuntu-root       lvm   a206ae07-c959-434b-a8a4-4fd46afc2d77
    └─vgubuntu-swap_1     lvm   d7f15c2d-1f6b-4bd6-9536-426ec27a620e
sdc                       disk  
├─sdc1                    part  
├─sdc2                    part  0C57-CD8C
├─sdc3                    part  f54aac74-c88d-4963-a23f-84d5b27c2829
└─sdc4                    part  86119b44-5b4a-4034-a761-52303f26b743
sdd                       disk  
├─sdd1                    part  E0DC5287DC5257BC
├─sdd2                    part  AA1A58321A57FA31
└─sdd3                    part  50B8C8FEB8C8E396
sr0                       rom
soriak
  • 303
  • 3
  • 11
  • Does your second install have UEFI boot entry in ESP on sdc? Or can you create one, by copying ESP from working drive & updating UUID in /EFI/ubuntu/grub.cfg to sdc's UUID Then you can configfile to that ESP which configfiles to install on sdc? See 6.5 on configfile details https://www.gnu.org/software/grub/manual/grub/grub.html#Multi_002dboot-manual-config Use labels and configfile to boot another install https://askubuntu.com/questions/344125/how-to-add-a-grub2-menu-entry-for-booting-installed-ubuntu-on-a-usb-drive/344359#344359 Do not know about encrypted booting. Do you need insmod luks – oldfred Dec 30 '20 at 00:16

1 Answers1

1

User Emmanual Rosa at unix.stackexchange.com has a pretty good answer:

    menuentry 'The Other Ubuntu' {
       insmod chain
       set root=(hd0,3)
       configfile /boot/grub/grub.cfg
    }

In the above example, I've made it so that the option shown during boot reads The Other Ubuntu. Feel free to change this to whatever you want it to say, by changing that first line, after the "menuentry" part, before the "{" character.

I feel I should mention, I've found this configuration can be a bit finicky at times, as GRUB doesn't always see my storage devices in the same order. One day, the partition in question could be located on "hd0", the next it could be "hd1", "hd2", etc. Generally, the partition number is the same, it's just the different "hd number" that's changed. However, if you find yourself adding, moving, or deleting partitions, your partition number could change, as well. Because of reasons like these, it's better to use UUIDs, instead. The code for doing so is a bit more complex, but you'll find an example below. For simplicity's sake, let's assume the partition with the soon-to-be-chainloaded GRUB instance has a UUID of 12345-abcdefg:

    menuentry 'The Other Ubuntu' {
       insmod chain
       if [ x$feature_platform_search_hint = xy ]; then
              search --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt3 --hint-efi=hd0,gpt3 --hint-baremetal=ahci0,gpt3  12345-abcdefg
           else
              search --no-floppy --fs-uuid --set=root 12345-abcdefg
       fi
       configfile /boot/grub/grub.cfg
    }

Since Ubuntu auto-rebuilds the GRUB configuration everytime a kernel is installed or removed (and Canonical releases new kernels regularly), it's best not to bother changing the /boot/grub/grub.cfg file by hand. Instead, add the code to the end of /etc/grub/40_custom, and run sudo update-grub.

I can personally vouch for this solution, as I've actually used this to add an Arch installation's GRUB to Ubuntu's GRUB. Since there's no easy way (AFAIK) to pass a RESUME= kernel parameter to Arch (for hibernating) without over-complicating Ubuntu's grub.cfg file, just putting it in Arch's GRUB (which doesn't change like Ubuntu's does), and hacking Arch's GRUB into Ubuntu's GRUB menu just made things easy for me.

PS: I realize that the OP knows the UUID of his/her second GRUB instance, but if anyone stumbling on this answer doesn't know the UUID of the partition containing their other grub, the lsblk command might be of use. Something like lsblk -o name,size,label,type,uuid should allow you to figure out which partition is which (especially if said partitions are labeled), and copy/paste a UUID from there.

TSJNachos117
  • 1,444
  • 2
  • 15
  • 19
  • Thanks for your reply and sorry for the delay. Unfortunately it didn't work. I updated my original question, to reflect the new behaviour. – soriak Jan 01 '21 at 12:04
  • This guide was written under the assumption that your /boot directory is part of your root filesystem. If you have /boot as a separate filesystem, you might need to change the last "configfile" line to something like: configfile /grub/grub.cfg. In other words, delete the "/boot" from the path. IDK if that's your problem, but this potential solution can't hurt, can it? – TSJNachos117 Jan 10 '21 at 03:40