1

Following on the "maintenance free" question here, I know there are ways to automatically generate grub2 menu entries, but I need to manually edit/add them from time to time, like

  • to a live-Linux system, or
  • when adding a new ISO boot entry (that exists on another disk).

Almost all grub2 intro docs use the form of

set root=(hd2,gpt7)

which I know will fail in my case, as I need to shuffle my HDs around between my machines from time to time, and the above format will surely break when that happens.

Despite the likelihood that I can't specify my root fs with a UUID (and failed here too), I don't want to use UUID either, because when I format a partition (when installing a new OS), that partition's UUID will change.

So what are the better options?

  1. Foremost, the GPT partition label is the best candidates, as I can make sure they are unique throughout all my machines, even when I shuffle my HDs around. However, there seems to be problem doing that: "I'm unable to mount the device using PARTLABEL".
    But, it should be promising, as I can see

Since 4.20, there's also support for PARTLABEL <github.com/torvalds/linux/blob/v4.20/init/do_mounts.c>, which I think is really convenient. Perhaps update the answer. – equaeghe Jan 20

  1. Second best would be PARTUUID. However, there are some confusing/conflicting answers floating on the Internet.
    • Here it says the format is PARTUUID=SSSSSSSS-PP, but it doesn't give an example what exactly it looks like,
    • the next answer gives an example but it says the format is root=PARTUUID=666c2eee-193d-42db-a490-4c444342bd4e

So, would using PARTLABEL or PARTUUID possible with the latest grub2?

xpt
  • 1,530
  • As far as I know, in order to select a specific partition, you would need to use the search command. Looking at the source, it supports labels and UUIDs of file-systems only. – Hermann Oct 17 '21 at 17:06
  • 1
    Good to know that searching the labels work, but how exactly to use it? I got 5 hits in the source, but that doesn't tell me much on how to use it. Thanks for helping, anyone. – xpt Oct 17 '21 at 18:14
  • 1
    Sorry, my comment was misleading. GRUB works on labels and UUIDs of file-systems (you stated you do not want those). It does not seem to have support for labels or UUIDs for GPT partitions (what you asked for). I am afraid, it is not possible to achieve what you want with GRUB. – Hermann Oct 17 '21 at 19:55
  • Ok, that, I can accept as the reality and the answer. Thanks @Hermann. – xpt Oct 17 '21 at 21:05

1 Answers1

1

Checkout grub2's configfile type file & entries.

I always forgot to run sudo update-grub when editing it for a new ISO. So I moved all entries to a text file in my ISO folder and one configfile entry in standard grub 40_custom. I then only have to edit the text file.

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

Shows a 40_custom to configfile into text file in ISO folders, one on hd0 & other on hd1. I have ISO on one drive to install to the other drive with less issues.

https://ubuntuforums.org/showthread.php?t=2076205&p=13788092#post13788092

https://www.gnu.org/software/grub/manual/grub/grub.html#Multi_002dboot-manual-config

Typical entry in 40_custom, never changes:

menuentry 'Live ISOs on SSD' {
search --set=root --label iso_ssd --hint hd1,gpt5
configfile /livecdimage.cfg
} 

Then in livecdimage.cfg or whatever file you want, copy complete grub2 boot stanza for ISO or other installs. Any grub stanza can be in the text file.

Another example:

https://ubuntuforums.org/showthread.php?t=2076205&p=14020961#post14020961

Example of my configfile named as livecdimage.cfg, typically has multipe entries or many ISO in ISO folder:

# livecdimage.cfg

menuentry "Kubuntu 21.10 Impish Live ISO" { set isofile="/ISO/kubuntu-21.10-desktop-amd64.iso" loopback loop (hd1,5)$isofile linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$isofile toram noeject initrd (loop)/casper/initrd }

oldfred
  • 650
  • Thanks oldfred! In https://ubuntuforums.org/showthread.php?t=2076205&p=13787835#post13787835 you said, "I use a configfile to boot the grub of my other Ubuntu installs...You can then have two entries, one to directly boot kernel, and one to configfile to that installs grub with all its entries." Would you elaborate them here and show what's inside your (hd2,gpt12)/boot/grub/grub.cfg and (hd1,6)/livecdimage.cfg file please? I need the content of those two files to understand the whole picture. thx. – xpt Oct 18 '21 at 02:05
  • Example posted above. I have examples with different hdX, gptXY as I have several systems and full installs on multiple flash drives that also boot ISO. Have not been consistent in examples. Getting drive & path correct are my bigger issues. Drive or hdX changes, if I reboot, or may depend on booting from hd0, hd1, hd2. And then order changes. Often when it does not work, it just use e in grub menu (even in configfile) while booting & edit hdX to another number till it works. Lots of boot examples by many users in the Ubuntu forum thread. – oldfred Oct 18 '21 at 02:43
  • Thanks! Interesting, you are using menuentry within menuentry (while previously I thought livecdimage.cfg is only part of the menuentry settings). One more question, the search --set=root in menuentry 'Live ISOs on SSD' will set root='(hd1,5)', so why still hard code (hd1,5) in your livecdimage.cfg instead of using $root directly? – xpt Oct 18 '21 at 04:47
  • I try to follow grub's own examples on set root. But the grub example seem to have changed over time. You can use whatever works. Not sure what is preferred method. – oldfred Oct 18 '21 at 14:02