Grub2 : how to list BLSCFG menu entries on Host OS shell (bash) (not grub) command line?

On my Fedora-40 Linux x86_64 laptop box, /boot/grub2/grub.cfg is configured to use BLSCFG - could anyone please explain more about BLSCFG , and how I might use it from bash command line to list menu entries so that I can use grub2-reboot command, giving menu entry number ?

    [root@host:~] # cat /etc/default/grub
    GRUB_TIMEOUT=5
    GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
    GRUB_DEFAULT="saved"
    #GRUB_DISABLE_SUBMENU="true"
    GRUB_TERMINAL_OUTPUT="console"
    GRUB_CMDLINE_LINUX="resume=UUID=${elided} rd.lvm.lv=LNX_ROOT/FEDORA rhgb=no plymouth.use-simpledrm enforcing=0 gnome.initial-setup=no mitigations=off "
    #GRUB_DISABLE_RECOVERY="true"
    GRUB_ENABLE_BLSCFG="true"
    #GRUB_DISABLE_OS_PROBER="true"
    GRUB_GRUBENV_UPDATE="yes"
    GRUB_OS_PROBER_SKIP_LIST="C08C-8F0D@/EFI/Microsoft/Boot/bootmgfw.efi"

The problem is, my /boot/grub2/grub.cfg thus uses DYNAMIC menu-entries , ie. BLSCFG looks at what is in the /boot/vmlinux* on the target boot device and then chooses the latest / last booted entry ?

Then how can I tell FC-40 to ‘reboot to selected grub menu entry’ with the grub2-reboot command , if I cannot list the menu entries ?

I want to ensure, if ‘lernel-install add …’ has rebuilt the Rescue kernel initramfs & done UEFI cfg updates AFTER it has rebuilt the non-rescue kernel images & done its cfg, then the non-rescue kernel remains the default next boot kernel, or I can SET the default next boot kernel with grub2-reboot . How, precisely can I do this if BLSCFG is in use ?

ie. I am looking for some ‘grub2-show-menu-entries’ shell script / command , that displays menu entry index #s I can pass to grub2-reboot …

Added bash

I don’t know how to set the index for the next boot dynamically which seems to be what you are asking. If the grub menu is displayed it is easy to select on-screen, or the default index can be set. But selecting the entry dynamically from a script or the cli seems difficult at best.

Grub works from the configuration file and is loaded by the bios before the os is loaded, so it cannot be controlled from the OS, but only by using the config file.

Note that the GRUB_DEFAULT="saved" entry (which can also be set to an index number) sets the default to be booted without using the grub menu and that then gets put into the grub.cfg file when running grub2-mkconfig. Changes are not dynamic since it must be saved into the grub.cfg file before rebooting.

the rescue kernel will never be the default boot kernel. It’s always the last entry.

sudo grubby --info=ALL

1 Like

Then I think at least the ‘grub2-reboot’ command manual page is in need of a major overhaul ?

RE: > that then gets put into the grub.cfg file when running grub2-mkconfig

No, NO proper grub Menu Entry syntax text sections are added to /boot/grub2/grub.cfg
except those I added manully in a local /etc/grub.d/ conf file for my bootable VMs .

This is the problem - yes , it is easy to parse the menu entries if they exist, but they don’t.

ie. maybe I should raise a grub2 “Request for Improvement” bugzilla:

“Provide a method to store and list the Sequence of Grub Menu Entries if BLSCFG==true is set” :

Couldn’t grub2+, IFF BLSCFG is true (set) (and perhaps if some new
GRUB_XML_MENU=/boot/grub2/Menu.xml" is set ?), write a /boot/grub2/Menu.xml file with
the ( Sequence #, Name, VM Linux Path, Boot Args) for each Menu entry as XML nodes,
on each boot, with the chosen entry with a “Selected=true” node / attribute, then this file could be
very easily parsed by any script.

RE:

Yes, this what I was looking for, thanks!

But best longterm method would be if grub would write some permanent record of
the actual generated menu entry list used, together with which was the selected entry.

But that’s the whole point, with BLSCFG enabled there is no need to have extra entries in grub.cfg & Co.
AFAIK, the grub loader compiles the list on-the-fly and does not rely anymore on fixed entries that could get misconfigured.
see /boot/grub2/grub.cfg

insmod blscfg
blscfg

and the comments in this file regarding blscfg.

I did not try to use grub2-reboot, so I don´t know it it works with BLSCFG, but you can change settings with grubby and change the default kernel or kernel-index to something else, not for the next boot only, though.

e.g. sudo grubby -set-default-index=1 would boot the 2nd kernel in the list.

Aha, I found /boot/loader/*.conf !

Wouldn’t it be nice if Grub would do something like create the link :

     /boot/loader/current.conf -> ${the conf file for the currently booted kernel}

?

Why?
Use grubby’s output and if you need this in a file then redirect the output to a tmp file.

sudo grubby --info=/boot/vmlinuz-$(uname -r)
index=0
kernel=“/boot/vmlinuz-6.10.7-200.fc40.x86_64”
args=“ro rootflags=subvol=root quiet rd.driver.blacklist=nouveau modprobe.blacklist=nouveau $tuned_params”
root=“UUID=85c7ead2-fd7d-4168-8094-2d666ca20d35”
initrd=“/boot/initramfs-6.10.7-200.fc40.x86_64.img $tuned_initrd”
title=“Fedora Linux (6.10.7-200.fc40.x86_64) 40 (Workstation Edition)”
id=“567c7e0e03b242e4b5d672cc22fffe54-6.10.7-200.fc40.x86_64”