How do you setup boot variants

I’ve got my multi-gpu setup working and I’d like to have 2 options during the boot (grub2):

  1. As normal, both gpus available
  2. One gpu passed through for vm, iommu enabled

I have successfully set those individually but I’d like to have a list for choosing a suitable variant on system start, depending whether I need both gpus for computing the 3d renders, or whether I need the secondary gpu in VM (when I need to launch a cad app in vm, as sadly there are no designer cad apps on Linux and the ones I use, for example Rhino, are very buggy in Wine even if I manage to start them).

How should I approach that? My guess is that I should modify /etc/default/grub file somehow, in a manner similar to the one I do when setting up passthrough, but I have no clue how.

ok, so basically what I’d like to achieve is to have 2 menu entries on system start. BOth almost identical. The only difference (apart from name - would be cool to name one “Multi GPU” and other “Pcie Passthrough” for example) would be that one would have “intel_iommu=on” added to kernel parameters.
Also it would be best to set it up so it won’t break after kernel update.
I’ve spent last hour going through various resources hinting it is doable but none showed how. Usually they’ve concentrated on something else. Any suggestions are welcome. At this point I’m not even sure whether it needs /etc/default/grub modification only or setting up /etc/grub.d/ script.

Currently grub.cfg is dynamically (re-)generated by running scripts in /etc/grub.d. So yes, to have second set of menu entries you would need to have script in /etc/grub.d that would emit these entries.

It may be possible to (ab-)use recovery menu entries by setting GRUB_CMDLINE_LINUX_RECOVERY, but then titles will be confusing (it will name menu entry “…(recovery)” which does not match intended purpose anymore.

I’ve came across this one:
https://docs-old.fedoraproject.org/en-US/Fedora/25/html/System_Administrators_Guide/sec-Using_only_a_Custom_Menu.html

so far it is the best guide I’ve found (at least for what I want to achieve). Before committing the changes I’ll post what I did here so hopefully someone more experienced could review those :slight_smile: .

I would do that in “/etc/grub.d/40_custom”.

I would take a few lines from “grub.cfg” and copy them there. Then I would modify as desired. And I would have them use the symlinks “vmlinuz” and “initrd” in “/boot” rather than the explicit kernel version, because that way I would not need to keep editing my changes on every kernel update.

thx @nrickert . That’s the part I’m missing - I thought I had to do it some “special” way to make those changes “stick” after kernel update. So far I assume the entries would look something like that:

menuentry 'openSUSE Leap 42.3 - NO IOMMU'  --class opensuse --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-3d697a71-17d6-4e7f-80df-2a202bc82583' {
	load_video
	set gfxpayload=keep
	insmod gzio
	insmod part_gpt
	insmod ext2
	set root='hd0,gpt2'
	if  x$feature_platform_search_hint = xy ]; then
	  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt2 --hint-efi=hd0,gpt2 --hint-baremetal=ahci0,gpt2  391753fe-f39e-414b-92dc-505c512f73ae
	else
	  search --no-floppy --fs-uuid --set=root 391753fe-f39e-414b-92dc-505c512f73ae
	fi
	echo	'Wczytywanie systemu Linux 4.4.104-39-default...'
	linuxefi /vmlinuz-4.4.104-39-default root=UUID=3d697a71-17d6-4e7f-80df-2a202bc82583 ro  resume=/dev/disk/by-uuid/0addf297-4cab-4973-8faa-d6338dc8b573 splash=silent quiet showopts
	echo	'Wczytywanie początkowego dysku RAM...'
	initrdefi /initrd-4.4.104-39-default
}

menuentry 'openSUSE Leap 42.3 - IOMMU ON'  --class opensuse --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-3d697a71-17d6-4e7f-80df-2a202bc82583' {
	load_video
	set gfxpayload=keep
	insmod gzio
	insmod part_gpt
	insmod ext2
	set root='hd0,gpt2'
	if  x$feature_platform_search_hint = xy ]; then
	  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt2 --hint-efi=hd0,gpt2 --hint-baremetal=ahci0,gpt2  391753fe-f39e-414b-92dc-505c512f73ae
	else
	  search --no-floppy --fs-uuid --set=root 391753fe-f39e-414b-92dc-505c512f73ae
	fi
	echo	'Wczytywanie systemu Linux 4.4.104-39-default...'
	linuxefi /vmlinuz-4.4.104-39-default root=UUID=3d697a71-17d6-4e7f-80df-2a202bc82583 ro  resume=/dev/disk/by-uuid/0addf297-4cab-4973-8faa-d6338dc8b573 splash=silent quiet showopts intel_iommu=on
	echo	'Wczytywanie początkowego dysku RAM...'
	initrdefi /initrd-4.4.104-39-default
}


  • the remaining submenu entries from grub.cfg .

So 2 questions:

  1. Are the remaining submenu etc entries from grub.cfg needed in my 40_custom file? If I understand the structure correctly it seems I should add only my custom menu entries there.
  2. How I modify my custom entries so they would pick new kernel after updating?

You only need the submenus if you need to be able to boot to an older kernel.

If you change “vmlinuz-4.4.104-39-default” to just “vmlinuz”, and change “initrd-4.4.104-39-default” to just “initrd”, then you won’t have problems after a kernel update. The kernel update changes those symlinks to the newest kernel, so you will always get that. And you can manually change them back to an older kernel if the newest kernel turns out to be broken, though you will lose your manual change on the next kernel update.

Menu entry ID is supposed to be unique. If you copy existing menu entry you should really change ID to something different. This allows using these ID to set default entry later.