bugGNU GRUB - Bugs: bug #39306, Contrib: grub-list-kernels.pl...


You are not allowed to post comments on this tracker with your current authentication level.

bug #39306: Contrib: grub-list-kernels.pl script

Submitted by:  Craig Sanders <csanders>
Submitted on:  Fri 21 Jun 2013 01:03:15 AM UTC  
Category:  None Severity:  Major
Priority:  5 - Normal Item Group:  Feature Request
Status:  Invalid Privacy:  Public
Assigned to:  None Originator Name: 
Open/Closed:  Closed Release: 
Release:  other Reproducibility:  None
Planned Release:  None

( Jump to the original submission)

Fri 21 Jun 2013 11:27:05 PM UTC, comment #9: 

OK, then tell me how else I can get a list of menuentries without having to reboot.

Without such a list, grub-set-default and grub-reboot are effectively useless.

I wrote my script because I had a need for it, and there was nothing else to do the job.  It's a useful tool that I would have expected should come with grub (and the absence of such a tool IS a bug), but it doesn't so I had to write my own.

Various versions of it have served me well for well over 10 years, starting with a version I wrote for legacy grub to extract the info from /boot/grub/menu.lst not long after i switched from LILO to grub in the late 90s.

It might be possible to run a loop as you describe in grub.cfg itself, but I have never seen it on any of hundreds of systems over the years - I don't think anyone actually uses that feature. 

certainly not me, or any of the linux distros I use...all menu entries I've ever seen in grub.cfg (and earlier in menu.lst) are generated as static entries by update-grub/grub-mkconfig (sort of like at "compile-time" rather than run-time)

Craig Sanders <csanders>
Fri 21 Jun 2013 02:08:40 AM UTC, comment #8: 

This is not a right place to contribute. This is a bug tracker. For contributions use grub-devel@gnu.org. The script is not acceptable as-is as it would encourage bad practice (use of indices). Another problem is the language: we don't use perl at all and introducing a new dependency for a secondary script is not an option. Changing to 'Invalid' since it's not a bug report. The task you've chosen is not fully solvable since menus can be generated dynamically, consider following:
for x in (*); do
   if [ -f $x/vmlinuz ]; then
      menuentry "Boot vmlinuz from $x" --menuentry-id "$x" "$x" {
            set root=$1
            linux /vmlinuz
You can't even know how mayn entries this generates and depending on this all the following indices may shift as well, yet another reason not to use indices.
I'd happily discuss this and other issues but as I said this is not a right place.
As to whether you want to walk away, it's really your choice, I was just pointing out that your solution doesn't fit into correct usage of concerned parts.

Vladimir Serbinenko <phcoder>
Project Administrator
Fri 21 Jun 2013 01:54:53 AM UTC, comment #7: 

Thank you for making my attempt to contribute something to the GNU Grub project such a pleasant and rewarding experience.

I'll know not to bother in future.

Craig Sanders <csanders>
Fri 21 Jun 2013 01:51:31 AM UTC, comment #6: 

re: comment #3 - yes, i understand how they're generated.

however if you run 'grub-set-default gnulinux-3.8-2-amd64-advanced-db4cb9bd-e5e9-40c6-ac22-2267fd41084d' and then later delete the kernel, the default in grubenv will point to a kernel that is no longer installed.  same as if you use the index and then delete the kernel.

in other words, you need to check that your saved_entry or prev_saved_entry is valid every time you run update-grub/grub-mkconfig whether you use a numbered index or a $menu_id_option.

which, again, is the point of my script.  it makes that task much less of a hassle.

BTW, if menuentry_id_option was mandatory for every menuentry, it would be trivial to modify the grub-list-kernels.pl script so that it printed them instead of a numeric index...but it's not mandatory, it's optional, so you can't rely on it being there.

Craig Sanders <csanders>
Fri 21 Jun 2013 01:47:51 AM UTC, comment #5: 

our version of 30_os-prober generates ids. Other scripts you mention are not ours at all. For them you can use menuentry titles for now and contact their distribuotrs to provide ids.

Vladimir Serbinenko <phcoder>
Project Administrator
Fri 21 Jun 2013 01:39:08 AM UTC, comment #4: 

BTW, looking at various grub.cfg files on my own systems, it looks like it's only the 10_linux, 20_linux_xen, and 30_uefi-firmware scripts that generate a $menuentry_id_option for each menuentry.

Other grub.d scripts (e.g. 30_os-prober, 20_ipxe, and others) don't generate them.

Since they're optional, it doesn't seem possible to rely on them being present.

Craig Sanders <csanders>
Fri 21 Jun 2013 01:37:54 AM UTC, comment #3: 

the IDs after $menuentry_id_option are stable. They are generated from root uuid and kernel name both of which are stable.

Vladimir Serbinenko <phcoder>
Project Administrator
Fri 21 Jun 2013 01:29:07 AM UTC, comment #2: 

if you mean $menuentry_id_option, then that's no more 'stable' than the indexes.  i.e. they can both change when a menuentry is added or removed.

That's most of the point of this script - so you can list the current menuentries after update-grub and then run grub-set-default or grub-reboot if required.

without this script, you have to do something like egrep 'submenu|menuentry' /boot/grub/grub.cfg and extract the menuentry_id_option or count the menus and submenus yourself.

Craig Sanders <csanders>
Fri 21 Jun 2013 01:07:47 AM UTC, comment #1: 

Indices are not stable and should never be recommended to use. ID should be used instead.

Vladimir Serbinenko <phcoder>
Project Administrator
Fri 21 Jun 2013 01:03:15 AM UTC, original submission:  

Script to list menu entries in grub.cfg, with indexes suitable for use with grub-set-default and grub-reboot (e.g. grub-set-default '1>0').  Includes support for grub submenus.

If required, I'm happy to assign copyright to FSF.

for more info, see http://blog.taz.net.au/2013/06/20/grub-list-kernels-pl/

Example output:

# grub-list-kernels.pl
   0    Debian GNU/Linux
   1    Advanced options for Debian GNU/Linux
1>0    Debian GNU/Linux, with Linux 3.9-1-amd64
1>1    Debian GNU/Linux, with Linux 3.9-1-amd64 (recovery mode)
1>2    Debian GNU/Linux, with Linux 3.8-2-amd64
1>3    Debian GNU/Linux, with Linux 3.8-2-amd64 (recovery mode)
1>4    Debian GNU/Linux, with Linux 3.8-1-amd64
1>5    Debian GNU/Linux, with Linux 3.8-1-amd64 (recovery mode)
1>6    Debian GNU/Linux, with Linux 3.7-trunk-amd64
1>7    Debian GNU/Linux, with Linux 3.7-trunk-amd64 (recovery mode)
1>8    Debian GNU/Linux, with Linux 3.2.0-4-amd64
1>9    Debian GNU/Linux, with Linux 3.2.0-4-amd64 (recovery mode)
   2    Network boot (iPXE)
   3    Bootable floppy: LSI
   4    Bootable floppy: freedos-bare

  Default: 0  "Debian GNU/Linux"

Craig Sanders <csanders>


Attached Files
file #28371:  grub-list-kernels.pl added by csanders (3KiB - application/download)


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by phcoder (Posted a comment)
  • -email is unavailable- added by csanders (Submitted the item)

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.




    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2013-06-21 phcoder StatusWont Fix => Invalid
    2013-06-21 phcoder StatusNone => Wont Fix
        Open/ClosedOpen => Closed
    2013-06-21 csanders Attached File- => Added grub-list-kernels.pl, #28371

    Back to the top

    Powered by Savane 3.6