Below is a patch for adding submenu support to 10_linux (grub-mkconfig). This is *not* the patch which Ubuntu has been carying for submenu support and so I'd especially like feedback from Ubuntu folks.
With GRUB_ENABLE_SUBMENUS=true in /etc/default/grub this patch will create a simple primary menu entry without any information about the kernel version in the title. Something like "Debian GNU/Linux". Below this main entry will be a submenu titled "Advanced options for Debian GNU/Linux". Selecting this entry will get you a list of all of the menu entries as they would be listed for that OS if submenus weren't enabled. So the submenu will contain an entry for every kernel version (including the one which would be booted by the main entry, so there is a duplication there) and recovery mode entries (if GRUB_DISABLE_RECOVERY != true) with the normal inclusion of the kernel version in the titles. This patch only affects 10_linux. If it's agreed that it's sound I will make similar patches for 20_xen and for the other 10_* where it is appropriate but I won't be able to test those easily myself. I'll also make a patch for 30_os-prober (which I will be able to test easily) and for grub.texi. I would have liked to have those already done but I've been pretty busy. I should be able to get the rest made by the end of this week. What follows is my reasoning for differing from Ubuntu in this case. It's longer than I expected it to be when I started writing this email, and isn't important to the contents of the patch itself, so if you'd just like to review the changes for sanity you can skip to the patch. This is contrasted with Ubuntu's patch which has an entry for the newest kernel (with kernel version included in the title), a recovery mode entry for the same version, then a submenu with all previous versions. The main reasons I dislike this approach are 1: Most people don't need to know the kernel version they're booting by default 2: Including the kernel version by default means that a user can't simply use GRUB_DEFAULT="Debian GNU/Linux" to specify that they want the newest Debian kernel to be booted by default. Other differences from Ubuntu's patch: This patch makes submenus optional. If you don't add GRUB_ENABLE_SUBMENUS=true to /etc/default/grub then nothing will change because of this patch. This patch makes defaults and saved defaults more intuative and useful. In addition to being able to simply use GRUB_DEFAULT="Debian GNU/Linux" you can also specify that you would like what *currently* happens to be the newest kernel to be used in the future as well, even if a newer kernel gets installed. With this patch you could use GRUB_DEFAULT="Advanced options for Debian GNU/Linux>Debian GNU/Linux with Linux 3.2.0-17". With Ubuntu you might try GRUB_DEFAULT="Ubuntu with Linux 3.2.0-17" but the moment a newer kernel is installed that entry will need to change to "Previous Linux versions>Ubuntu with Linux 3.2.0-17". This patch also makes saved defaults more intuitive and useful because if a user chooses simply "Debian GNU/Linux", and they're using GRUB_SAVEDEFAULT=true, they probably want and expect that on the next boot this same entry will be selected again, even if it represents a newer kernel version. If however the user decides to choose "Advanced options for Debian GNU/Linux>Debian GNU/Linux with Linux 3.2.0-17" they probably want and expect the exact same kernel version to be the default for the next boot. This patch adds indentation for "menuentry" commands within the submenu in the grub.cfg, to make the grub.cfg more readable. This patch creates a predictable number of menu entries in the main menu. One main entry and one submenu. With Ubuntu if you had more than one kernel version you'd get one default entry for the newest, one recovery mode entry for the newest, and a submenu. If you only had one kernel version the submenu would be omitted. -- Jordan Uggla (Jordan_U on irc.freenode.net) === modified file 'util/grub-mkconfig.in' --- util/grub-mkconfig.in 2012-02-26 17:37:54 +0000 +++ util/grub-mkconfig.in 2012-02-27 08:22:48 +0000 @@ -206,7 +206,8 @@ GRUB_INIT_TUNE \ GRUB_SAVEDEFAULT \ GRUB_ENABLE_CRYPTODISK \ - GRUB_BADRAM + GRUB_BADRAM \ + GRUB_ENABLE_SUBMENUS if test "x${grub_cfg}" != "x"; then rm -f "${grub_cfg}.new" === modified file 'util/grub.d/10_linux.in' --- util/grub.d/10_linux.in 2012-02-26 16:28:05 +0000 +++ util/grub.d/10_linux.in 2012-02-27 08:55:21 +0000 @@ -63,15 +63,25 @@ { os="$1" version="$2" - recovery="$3" + type="$3" args="$4" - if ${recovery} ; then - title="$(gettext_quoted "%s, with Linux %s (recovery mode)")" + + case $type in + simple) + title="$(gettext_quoted "%s")" ;; + recovery) + title="$(gettext_quoted "%s, with Linux %s (recovery mode)")" ;; + *) + title="$(gettext_quoted "%s, with Linux %s")" ;; + esac + + if [ "x$type" = "xsimple" ]; then + printf "menuentry '${title}' ${CLASS} {\n" "${os}" else - title="$(gettext_quoted "%s, with Linux %s")" + printf "menuentry '${title}' ${CLASS} {\n" "${os}" "${version}" fi - printf "menuentry '${title}' ${CLASS} {\n" "${os}" "${version}" - if ! ${recovery} ; then + + if [ x$type != xrecovery ] ; then save_default_entry | sed -e "s/^/\t/" fi @@ -145,6 +155,11 @@ prepare_boot_cache= prepare_root_cache= +# Extra indentation to add to menu entries in a submenu. We're not in a submenu +# yet, so it's empty. In a submenu it will be equal to '\t' (one tab). +submenu_indentation="" + +is_first_entry=true while [ "x$list" != "x" ] ; do linux=`version_find_latest $list` gettext_printf "Found linux image: %s\n" "$linux" >&2 @@ -189,12 +204,32 @@ linux_root_device_thisversion=${GRUB_DEVICE} fi - linux_entry "${OS}" "${version}" false \ - "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" + if [ "x$GRUB_ENABLE_SUBMENUS" = xtrue -a "x$is_first_entry" = xtrue ]; then + linux_entry "${OS}" "${version}" simple \ + "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" + + submenu_indentation="\t" + + cat << EOF +submenu '$(gettext_quoted "Advanced options for ${OS}")' { +EOF + fi + + linux_entry "${OS}" "${version}" advanced \ + "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" \ + | sed "s/^/$submenu_indentation/" if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then - linux_entry "${OS}" "${version}" true \ - "single ${GRUB_CMDLINE_LINUX}" + linux_entry "${OS}" "${version}" recovery \ + "single ${GRUB_CMDLINE_LINUX}" \ + | sed "s/^/$submenu_indentation/" fi list=`echo $list | tr ' ' '\n' | grep -vx $linux | tr '\n' ' '` + is_first_entry=false done + +# If submenus are enabled, and at least one kernel was found, then we need to +# add a closing '}' for the submenu command. +if [ x"$GRUB_ENABLE_SUBMENUS" = xtrue -a x"$is_first_entry" != xtrue ]; then + echo '}' +fi _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel