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)
|
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
}
fi
done
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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:
|