I quite often see requests for an equivalent for the 'howmany' option implemented in the update-grub script in Debian's GRUB Legacy packaging: emit only so many native kernels, so that you could say howmany=2 to avoid cluttering the menu with entries for more than two kernels even if you haven't got round to removing the older ones yet. I don't know if I'd use this myself but it seems like a pretty reasonable request. Here's a patch to implement it, in what seemed fairly close to GRUB 2 style.
2010-07-13 Colin Watson <cjwat...@ubuntu.com> * util/grub-mkconfig.in: Export GRUB_COUNT_HURD, GRUB_COUNT_KFREEBSD, GRUB_COUNT_LINUX, GRUB_COUNT_NETBSD, and GRUB_COUNT_XEN. * util/grub.d/10_hurd.in: If GRUB_COUNT_HURD is set, only process that many kernels. * util/grub.d/10_kfreebsd.in: If GRUB_COUNT_KFREEBSD is set, only process that many kernels. * util/grub.d/10_linux.in: If GRUB_COUNT_LINUX is set, only process that many kernels. * util/grub.d/10_netbsd.in: If GRUB_COUNT_NETBSD is set, only process that many kernels. * util/grub.d/20_linux_xen.in: If GRUB_COUNT_XEN and/or GRUB_COUNT_LINUX are set, only process that many hypervisors and kernels respectively. * docs/grub.texi (Simple configuration): Document GRUB_COUNT_HURD, GRUB_COUNT_KFREEBSD, GRUB_COUNT_LINUX, GRUB_COUNT_NETBSD, and GRUB_COUNT_XEN. === modified file 'docs/grub.texi' --- docs/grub.texi 2010-07-05 10:08:04 +0000 +++ docs/grub.texi 2010-07-13 00:51:11 +0000 @@ -1064,6 +1064,24 @@ only to the default menu entry, after th As @samp{GRUB_CMDLINE_LINUX} and @samp{GRUB_CMDLINE_LINUX_DEFAULT}, but for NetBSD. +...@item GRUB_COUNT_HURD +The number of Hurd kernels for which @command{grub-mkconfig} should generate +menu entries. Unset by default, meaning to generate menu entries for all +kernels. (This excludes menu entries generated by @command{os-prober} for +other operating systems installed on the same system.) + +...@item GRUB_COUNT_KFREEBSD +As @samp{GRUB_COUNT_HURD}, but for FreeBSD kernels. + +...@item GRUB_COUNT_LINUX +As @samp{GRUB_COUNT_LINUX}, but for Linux kernels. + +...@item GRUB_COUNT_NETBSD +As @samp{GRUB_COUNT_HURD}, but for NetBSD kernels. + +...@item GRUB_COUNT_XEN +As @samp{GRUB_COUNT_HURD}, but for Xen hypervisors. + @item GRUB_DISABLE_LINUX_UUID Normally, @command{grub-mkconfig} will generate menu entries that use universally-unique identifiers (UUIDs) to identify the root filesystem to === modified file 'util/grub-mkconfig.in' --- util/grub-mkconfig.in 2010-06-29 15:20:49 +0000 +++ util/grub-mkconfig.in 2010-07-13 00:39:38 +0000 @@ -262,6 +262,11 @@ export GRUB_DEFAULT \ GRUB_CMDLINE_XEN_DEFAULT \ GRUB_CMDLINE_NETBSD \ GRUB_CMDLINE_NETBSD_DEFAULT \ + GRUB_COUNT_HURD \ + GRUB_COUNT_KFREEBSD \ + GRUB_COUNT_LINUX \ + GRUB_COUNT_NETBSD \ + GRUB_COUNT_XEN \ GRUB_TERMINAL_INPUT \ GRUB_TERMINAL_OUTPUT \ GRUB_SERIAL_COMMAND \ === modified file 'util/grub.d/10_hurd.in' --- util/grub.d/10_hurd.in 2010-06-29 15:20:49 +0000 +++ util/grub.d/10_hurd.in 2010-07-13 00:45:55 +0000 @@ -36,7 +36,14 @@ all_of_them=true # FIXME: add l4 here? kernel= +count=0 for i in /boot/gnumach* ; do + if test "x${GRUB_COUNT_HURD}" != "x" && \ + test "${count}" -ge "${GRUB_COUNT_HURD}"; then + break + fi + count="$((${count} + 1))" + if test -e $i ; then basename=`basename $i` dirname=`dirname $i` === modified file 'util/grub.d/10_kfreebsd.in' --- util/grub.d/10_kfreebsd.in 2010-06-29 15:20:49 +0000 +++ util/grub.d/10_kfreebsd.in 2010-07-13 00:43:14 +0000 @@ -80,8 +80,15 @@ list=`for i in /boot/kfreebsd-* /boot/ke if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi done` prepare_boot_cache= +count=0 while [ "x$list" != "x" ] ; do + if test "x${GRUB_COUNT_KFREEBSD}" != "x" && \ + test "${count}" -ge "${GRUB_COUNT_KFREEBSD}"; then + break + fi + count="$((${count} + 1))" + kfreebsd=`version_find_latest $list` echo "Found kernel of FreeBSD: $kfreebsd" >&2 basename=`basename $kfreebsd` === modified file 'util/grub.d/10_linux.in' --- util/grub.d/10_linux.in 2010-07-02 11:32:05 +0000 +++ util/grub.d/10_linux.in 2010-07-13 00:43:37 +0000 @@ -106,8 +106,15 @@ list=`for i in /boot/vmlinu[zx]-* /vmlin if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi done` prepare_boot_cache= +count=0 while [ "x$list" != "x" ] ; do + if test "x${GRUB_COUNT_LINUX}" != "x" && \ + test "${count}" -ge "${GRUB_COUNT_LINUX}"; then + break + fi + count="$((${count} + 1))" + linux=`version_find_latest $list` echo "Found linux image: $linux" >&2 basename=`basename $linux` === modified file 'util/grub.d/10_netbsd.in' --- util/grub.d/10_netbsd.in 2010-06-29 15:20:49 +0000 +++ util/grub.d/10_netbsd.in 2010-07-13 00:44:07 +0000 @@ -63,6 +63,7 @@ netbsd_entry () } prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE} | sed -e 's,^, ,')" +count=0 # We look for NetBSD kernels in / but not in subdirectories. We simply # pick all statically linked ELF executable files (or links) in / with a @@ -77,6 +78,12 @@ for k in $(ls -t /netbsd*) ; do continue fi + if test "x${GRUB_COUNT_NETBSD}" != "x" && \ + test "${count}" -ge "${GRUB_COUNT_NETBSD}"; then + break + fi + count="$((${count} + 1))" + echo "Found NetBSD kernel: $k" >&2 netbsd_entry "knetbsd" "$k" false "${GRUB_CMDLINE_NETBSD_DEFAULT}" netbsd_entry "multiboot" "$k" false "${GRUB_CMDLINE_NETBSD_DEFAULT}" === modified file 'util/grub.d/20_linux_xen.in' --- util/grub.d/20_linux_xen.in 2010-06-29 15:20:49 +0000 +++ util/grub.d/20_linux_xen.in 2010-07-13 00:45:55 +0000 @@ -95,15 +95,29 @@ xen_list=`for i in /boot/xen*; do if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi done` prepare_boot_cache= +xen_count=0 while [ "x${xen_list}" != "x" ] ; do + if test "x${GRUB_COUNT_XEN}" != "x" && \ + test "${xen_count}" -ge "${GRUB_COUNT_XEN}"; then + break + fi + xen_count="$((${xen_count} + 1))" + list="${linux_list}" current_xen=`version_find_latest $xen_list` xen_basename=`basename ${current_xen}` xen_dirname=`dirname ${current_xen}` rel_xen_dirname=`make_system_path_relative_to_its_root $xen_dirname` xen_version=`echo $xen_basename | sed -e "s,.gz$,,g;s,^xen-,,g"` + linux_count=0 while [ "x$list" != "x" ] ; do + if test "x${GRUB_COUNT_LINUX}" != "x" && \ + test "${linux_count}" -ge "${GRUB_COUNT_LINUX}"; then + break + fi + linux_count="$((${linux_count} + 1))" + linux=`version_find_latest $list` echo "Found linux image: $linux" >&2 basename=`basename $linux` -- Colin Watson [cjwat...@ubuntu.com] _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org http://lists.gnu.org/mailman/listinfo/grub-devel