There is a GRUB command, not documented in the manual, that precisely parses a config file, extracting the entries and ignoring the remainder of the configuration : extract_entries_source
. With this, any change to the secondary distribution's GRUB menu entries will be automatically taken into account in the main GRUB's menu.
In the main ("host") distribution
Add a custom entry in /etc/grub.d/40_custom
:
# A dummy entry to mark the separation
menuentry "Extracted from /dev/sdb2" {
true
}
# the following if for MBR disk, change to part_gpt if necessary
insmod part_msdos
# adapt with appropriate file system module
insmod ext2
# replace aaaa-bbbb-cccc with actual partition UUID
search --fs-uuid aaaa-bbbb-cccc --set slavegrub --no-floppy
extract_entries_source ($slavegrub)/boot/grub/grub.cfg
The partition's (file system's) UUID can be obtained with blkid
.
You will also want to prevent GRUB to automatically populate the menu with OS-prober. This is configured in /etc/default/grub
and can be disabled globally with GRUB_DISABLE_OS_PROBER
or selectively for some partitions with GRUB_OS_PROBER_SKIP_LIST
(see GRUB manual).
Then you can update-grub
.
In the secondary distribution
There is nothing to do as the /boot/grub/grub.cfg
file will only be read for its entries and will never be actually executed. You will probably want to disable the OS-prober completely there, as those entries would be redundant when integrated within the main GRUB's menu.