9

I was fiddling with my GRUB 2 config files (/boot/grub/grub.cfg) and I noticed that the menuentry line for the automatically added Ubuntu boot looks like this:

menuentry 'Ubuntu 14.04 Trusty Tahr (on sda5)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-fe3a2033-d77c-4d8c-ba04-3bb27b267dc2' {

What is that $menuentry_id_option 'gnulinux-simple-fe3a2033-d77c-4d8c-ba04-3bb27b267dc2' part at the end and do I need it when I add new boot options?

So, what does the $menuentry_id_option mean?
Do I need to use it when I add another boot menu item for some other distro?
What would happen if I didn't include it?

Also, is there some GRUB reference I can look to for questions about what these things do?

Robin
  • 282

2 Answers2

5

The line you are looking for is:

if [ x"${feature_menuentry_id}" = xy ]; then
  menuentry_id_option="--id"
else
  menuentry_id_option=""
fi

Gives you the value of feature_menuentry_id and if it's equal to y then it will add the --id parameter to your menu entries:

menuentry 'Ubuntu 14.04 Trusty Tahr (on sda5)' --class ubuntu --class gnu-linux --class gnu --class os --id 'gnulinux-simple-fe3a2033-d77c-4d8c-ba04-3bb27b267dc2' {

If it's not, then it will leave it as is:

menuentry 'Ubuntu 14.04 Trusty Tahr (on sda5)' --class ubuntu --class gnu-linux --class gnu --class os 'gnulinux-simple-fe3a2033-d77c-4d8c-ba04-3bb27b267dc2' {

The --id parameter for menuentry isn't defined in the manual for menuentry, but one can haphazardly guess is the UUID for the partition the kernel is supposed to boot from.

Braiam
  • 35,991
  • Ok. I didn't catch the connection with the if statement. I figured out the UUID part myself shortly after I asked the question. Thanks, answer accepted. – Robin Oct 30 '14 at 01:06
  • 2
    Woah. Undocumented option and if we don't want to use it, we have a dangling optionless string on the command line? This is dirty... – David Tonhofer Aug 08 '16 at 11:58
3

According to this mail: https://lists.gnu.org/archive/html/grub-devel/2013-01/msg00070.html

excerpt

> @@ -3135,6 +3136,9 @@
>  The @option{--hotkey} option associates a hotkey with a menu entry.
>  @var{key} may be a single letter, or one of the aliases @samp{backspace},
>  @samp{tab}, or @samp{delete}.
> +
> +The @option{--id} may be used to associate unique identifier with a menu entry. address@hidden is arbitrary string.

It has to be [a-zA-Z_][0-9a-zA-Z_]* (while arbitrary string would work it's not a good idea.

This option actually gives the menuentry a unique id, but is undocumented because it is not recommended. AFAIU, the partition UUID thing is merely a practice many distros follow in creating that id.

In Arch, for example, the format is "gnulinux-core repo kernel-true-{UUID}".

slm
  • 369,824
amosonn
  • 31
  • A wrinkle to this is that, because the --id option is both undocumented and (AFAICT) useless, distros don't always manage it quite correctly. For instance, Fedora's grubby boot-config-munger (which is run as part of every kernel package install, to edit grub.cfg directly, rather than using grub's grub2-mkconfig generator) just blindly copies the previous kernel's boot entry with some string-replacement on the kernel params. The result being that every menuentry has the exact same "unique" ID specified for it. – FeRD Mar 16 '18 at 04:43
  • (One unexpected feature of the Fedora menuid mismanagement I mentioned in my previous comment: Because the kernel version is encoded into the menuid when it's (properly) generated, you can get an idea of a Fedora install's age by looking at the menuid string that all of the menuentries are carrying around. For example, one of my home machines uses the menuid gnulinux-4.12.11-200.fc25.x86_64-advanced-<UUID> because I installed a new Fedora 25 root partition last year, as part of a primary hard drive upgrade.) – FeRD Mar 16 '18 at 04:55