dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

Blame SOURCES/0236-add-10_linux_bls-grub.d-snippet-to-generate-menu-ent.patch

8631a2
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
8631a2
From: Javier Martinez Canillas <javierm@redhat.com>
8631a2
Date: Wed, 3 Oct 2018 20:48:32 +0200
8631a2
Subject: [PATCH] add 10_linux_bls grub.d snippet to generate menu entries from
8631a2
 BLS files
8631a2
8631a2
This grub.d snippet can be used on platforms where the bootloader doesn't
8631a2
have BLS support and only can parse a normal grub configuration file.
8631a2
8631a2
Portions of this script were taken from the ostree-grub-generator script
8631a2
included in the OSTree project.
8631a2
8631a2
Resolves: rhbz#1636013
8631a2
8631a2
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
8631a2
---
8631a2
 Makefile.util.def           |   7 +
8631a2
 util/grub.d/10_linux_bls.in | 440 ++++++++++++++++++++++++++++++++++++++++++++
8631a2
 2 files changed, 447 insertions(+)
8631a2
 create mode 100644 util/grub.d/10_linux_bls.in
8631a2
8631a2
diff --git a/Makefile.util.def b/Makefile.util.def
8631a2
index cba4d500198..08cc98ddb8b 100644
8631a2
--- a/Makefile.util.def
8631a2
+++ b/Makefile.util.def
8631a2
@@ -502,6 +502,13 @@ script = {
8631a2
   condition = COND_HOST_LINUX;
8631a2
 };
8631a2
 
8631a2
+script = {
8631a2
+  name = '10_linux_bls';
8631a2
+  common = util/grub.d/10_linux_bls.in;
8631a2
+  installdir = grubconf;
8631a2
+  condition = COND_HOST_LINUX;
8631a2
+};
8631a2
+
8631a2
 script = {
8631a2
   name = '10_xnu';
8631a2
   common = util/grub.d/10_xnu.in;
8631a2
diff --git a/util/grub.d/10_linux_bls.in b/util/grub.d/10_linux_bls.in
8631a2
new file mode 100644
8631a2
index 00000000000..3cc7803c6a1
8631a2
--- /dev/null
8631a2
+++ b/util/grub.d/10_linux_bls.in
8631a2
@@ -0,0 +1,440 @@
8631a2
+#! /bin/sh
8631a2
+set -e
8631a2
+
8631a2
+# grub-mkconfig helper script.
8631a2
+# Copyright (C) 2006,2007,2008,2009,2010  Free Software Foundation, Inc.
8631a2
+#
8631a2
+# GRUB is free software: you can redistribute it and/or modify
8631a2
+# it under the terms of the GNU General Public License as published by
8631a2
+# the Free Software Foundation, either version 3 of the License, or
8631a2
+# (at your option) any later version.
8631a2
+#
8631a2
+# GRUB is distributed in the hope that it will be useful,
8631a2
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
8631a2
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
8631a2
+# GNU General Public License for more details.
8631a2
+#
8631a2
+# You should have received a copy of the GNU General Public License
8631a2
+# along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
8631a2
+
8631a2
+prefix="@prefix@"
8631a2
+exec_prefix="@exec_prefix@"
8631a2
+datarootdir="@datarootdir@"
8631a2
+
8631a2
+. "$pkgdatadir/grub-mkconfig_lib"
8631a2
+
8631a2
+export TEXTDOMAIN=@PACKAGE@
8631a2
+export TEXTDOMAINDIR="@localedir@"
8631a2
+
8631a2
+CLASS="--class gnu-linux --class gnu --class os --unrestricted"
8631a2
+
8631a2
+if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
8631a2
+  OS="$(eval $(grep PRETTY_NAME /etc/os-release) ; echo ${PRETTY_NAME})"
8631a2
+  CLASS="--class $(eval $(grep '^ID_LIKE=\|^ID=' /etc/os-release) ; [ -n "${ID_LIKE}" ] && echo ${ID_LIKE} || echo ${ID}) ${CLASS}"
8631a2
+else
8631a2
+  OS="${GRUB_DISTRIBUTOR}"
8631a2
+  CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1|LC_ALL=C sed 's,[^[:alnum:]_],_,g') ${CLASS}"
8631a2
+fi
8631a2
+
8631a2
+# loop-AES arranges things so that /dev/loop/X can be our root device, but
8631a2
+# the initrds that Linux uses don't like that.
8631a2
+case ${GRUB_DEVICE} in
8631a2
+  /dev/loop/*|/dev/loop[0-9])
8631a2
+    GRUB_DEVICE=`losetup ${GRUB_DEVICE} | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"`
8631a2
+  ;;
8631a2
+esac
8631a2
+
8631a2
+# Default to disabling partition uuid support to maintian compatibility with
8631a2
+# older kernels.
8631a2
+GRUB_DISABLE_LINUX_PARTUUID=${GRUB_DISABLE_LINUX_PARTUUID-true}
8631a2
+
8631a2
+# btrfs may reside on multiple devices. We cannot pass them as value of root= parameter
8631a2
+# and mounting btrfs requires user space scanning, so force UUID in this case.
8631a2
+if ( [ "x${GRUB_DEVICE_UUID}" = "x" ] && [ "x${GRUB_DEVICE_PARTUUID}" = "x" ] ) \
8631a2
+    || ( [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \
8631a2
+	&& [ "x${GRUB_DISABLE_LINUX_PARTUUID}" = "xtrue" ] ) \
8631a2
+    || ( ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \
8631a2
+	&& ! test -e "/dev/disk/by-partuuid/${GRUB_DEVICE_PARTUUID}" ) \
8631a2
+    || ( test -e "${GRUB_DEVICE}" && uses_abstraction "${GRUB_DEVICE}" lvm ); then
8631a2
+  LINUX_ROOT_DEVICE=${GRUB_DEVICE}
8631a2
+elif [ "x${GRUB_DEVICE_UUID}" = "x" ] \
8631a2
+    || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ]; then
8631a2
+  LINUX_ROOT_DEVICE=PARTUUID=${GRUB_DEVICE_PARTUUID}
8631a2
+else
8631a2
+  LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
8631a2
+fi
8631a2
+
8631a2
+case x"$GRUB_FS" in
8631a2
+    xbtrfs)
8631a2
+	if [ "x${SUSE_BTRFS_SNAPSHOT_BOOTING}" = "xtrue" ]; then
8631a2
+	GRUB_CMDLINE_LINUX="${GRUB_CMDLINE_LINUX} \${extra_cmdline}"
8631a2
+	else
8631a2
+	rootsubvol="`make_system_path_relative_to_its_root /`"
8631a2
+	rootsubvol="${rootsubvol#/}"
8631a2
+	if [ "x${rootsubvol}" != x ]; then
8631a2
+	    GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}"
8631a2
+	fi
8631a2
+	fi;;
8631a2
+    xzfs)
8631a2
+	rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true`
8631a2
+	bootfs="`make_system_path_relative_to_its_root / | sed -e "s,@$,,"`"
8631a2
+	LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs}"
8631a2
+	;;
8631a2
+esac
8631a2
+
8631a2
+mktitle ()
8631a2
+{
8631a2
+  local title_type
8631a2
+  local version
8631a2
+  local OS_NAME
8631a2
+  local OS_VERS
8631a2
+
8631a2
+  title_type=$1 && shift
8631a2
+  version=$1 && shift
8631a2
+
8631a2
+  OS_NAME="$(eval $(grep ^NAME= /etc/os-release) ; echo ${NAME})"
8631a2
+  OS_VERS="$(eval $(grep ^VERSION= /etc/os-release) ; echo ${VERSION})"
8631a2
+
8631a2
+  case $title_type in
8631a2
+    recovery)
8631a2
+      title=$(printf '%s (%s) %s (recovery mode)' \
8631a2
+                     "${OS_NAME}" "${version}" "${OS_VERS}")
8631a2
+      ;;
8631a2
+    *)
8631a2
+      title=$(printf '%s (%s) %s' \
8631a2
+                     "${OS_NAME}" "${version}" "${OS_VERS}")
8631a2
+      ;;
8631a2
+  esac
8631a2
+  echo -n ${title}
8631a2
+}
8631a2
+
8631a2
+title_correction_code=
8631a2
+
8631a2
+populate_header_warn()
8631a2
+{
8631a2
+cat <
8631a2
+
8631a2
+# This section was generated by a script. Do not modify the generated file - all changes
8631a2
+# will be lost the next time file is regenerated. Instead edit the BootLoaderSpec files.
8631a2
+
8631a2
+EOF
8631a2
+}
8631a2
+
8631a2
+read_config()
8631a2
+{
8631a2
+    config_file=${1}
8631a2
+    title=""
8631a2
+    initrd=""
8631a2
+    options=""
8631a2
+    linux=""
8631a2
+
8631a2
+    while read -r line
8631a2
+    do
8631a2
+        record=$(echo ${line} | cut -f 1 -d ' ')
8631a2
+        value=$(echo ${line} | cut -s -f2- -d ' ')
8631a2
+        case "${record}" in
8631a2
+            "title")
8631a2
+                title=${value}
8631a2
+                ;;
8631a2
+            "initrd")
8631a2
+                initrd=${value}
8631a2
+                ;;
8631a2
+            "linux")
8631a2
+                linux=${value}
8631a2
+                ;;
8631a2
+            "options")
8631a2
+                options=${value}
8631a2
+                ;;
8631a2
+        esac
8631a2
+    done < ${config_file}
8631a2
+}
8631a2
+
8631a2
+populate_menu()
8631a2
+{
8631a2
+    entries_path="/boot/loader/entries"
8631a2
+    gettext_printf "Generating boot entries from BLS files...\n" >&2
8631a2
+    for config in $(ls -v -r $entries_path/*.conf); do
8631a2
+        read_config ${config}
8631a2
+        menu="${menu}menuentry '${title}' {\n"
8631a2
+        menu="${menu}\t linux ${linux} ${options}\n"
8631a2
+        if [ -n "${initrd}" ] ; then
8631a2
+            menu="${menu}\t initrd ${boot_prefix}${initrd}\n"
8631a2
+        fi
8631a2
+        menu="${menu}}\n\n"
8631a2
+    done
8631a2
+    # The printf command seems to be more reliable across shells for special character (\n, \t) evaluation
8631a2
+    printf "$menu"
8631a2
+}
8631a2
+
8631a2
+linux_entry ()
8631a2
+{
8631a2
+  os="$1"
8631a2
+  version="$2"
8631a2
+  type="$3"
8631a2
+  isdebug="$4"
8631a2
+  args="$5"
8631a2
+
8631a2
+  if [ -z "$boot_device_id" ]; then
8631a2
+      boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
8631a2
+  fi
8631a2
+
8631a2
+  if [ "x${GRUB_ENABLE_BLSCFG}" = "xtrue" ]; then
8631a2
+    if [ x$dirname = x/ ]; then
8631a2
+      if [ -z "${prepare_root_cache}" ]; then
8631a2
+        prepare_grub_to_access_device ${GRUB_DEVICE}
8631a2
+      fi
8631a2
+    else
8631a2
+      if [ -z "${prepare_boot_cache}" ]; then
8631a2
+        prepare_grub_to_access_device ${GRUB_DEVICE_BOOT}
8631a2
+      fi
8631a2
+    fi
8631a2
+
8631a2
+    if [ -d /sys/firmware/efi ]; then
8631a2
+        bootefi_device="`${grub_probe} --target=device /boot/efi/`"
8631a2
+        prepare_grub_to_access_device ${bootefi_device} boot
8631a2
+    else
8631a2
+        boot_device="`${grub_probe} --target=device /boot/`"
8631a2
+        prepare_grub_to_access_device ${boot_device} boot
8631a2
+    fi
8631a2
+
8631a2
+    populate_header_warn
8631a2
+    populate_menu
8631a2
+
8631a2
+    ${grub_editenv} - set saved_entry=0
8631a2
+    ${grub_editenv} - set kernelopts="root=${linux_root_device_thisversion} ro ${args}"
8631a2
+
8631a2
+    exit 0
8631a2
+  fi
8631a2
+
8631a2
+  if [ x$type != xsimple ] ; then
8631a2
+      title=$(mktitle "$type" "$version")
8631a2
+      if [ x"$title" = x"$GRUB_ACTUAL_DEFAULT" ] || [ x"Previous Linux versions>$title" = x"$GRUB_ACTUAL_DEFAULT" ]; then
8631a2
+	  replacement_title="$(echo "Advanced options for ${OS}" | sed 's,>,>>,g')>$(echo "$title" | sed 's,>,>>,g')"
8631a2
+	  quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)"
8631a2
+	  title_correction_code="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;"
8631a2
+      fi
8631a2
+      if [ x$isdebug = xdebug ]; then
8631a2
+	  title="$title${GRUB_LINUX_DEBUG_TITLE_POSTFIX}"
8631a2
+      fi
8631a2
+      echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
8631a2
+  else
8631a2
+      echo "menuentry '$(echo "$os" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
8631a2
+  fi
8631a2
+  if [ x$type != xrecovery ] ; then
8631a2
+      save_default_entry | grub_add_tab
8631a2
+  fi
8631a2
+
8631a2
+  # Use ELILO's generic "efifb" when it's known to be available.
8631a2
+  # FIXME: We need an interface to select vesafb in case efifb can't be used.
8631a2
+  if [ "x$GRUB_GFXPAYLOAD_LINUX" = x ]; then
8631a2
+      echo "	load_video" | sed "s/^/$submenu_indentation/"
8631a2
+      if grep -qx "CONFIG_FB_EFI=y" "${config}" 2> /dev/null \
8631a2
+	  && grep -qx "CONFIG_VT_HW_CONSOLE_BINDING=y" "${config}" 2> /dev/null; then
8631a2
+	  echo "	set gfxpayload=keep" | sed "s/^/$submenu_indentation/"
8631a2
+      fi
8631a2
+  else
8631a2
+      if [ "x$GRUB_GFXPAYLOAD_LINUX" != xtext ]; then
8631a2
+	  echo "	load_video" | sed "s/^/$submenu_indentation/"
8631a2
+      fi
8631a2
+      echo "	set gfxpayload=$GRUB_GFXPAYLOAD_LINUX" | sed "s/^/$submenu_indentation/"
8631a2
+  fi
8631a2
+
8631a2
+  echo "	insmod gzio" | sed "s/^/$submenu_indentation/"
8631a2
+
8631a2
+  if [ x$dirname = x/ ]; then
8631a2
+    if [ -z "${prepare_root_cache}" ]; then
8631a2
+      prepare_root_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE} | grub_add_tab)"
8631a2
+    fi
8631a2
+    printf '%s\n' "${prepare_root_cache}" | sed "s/^/$submenu_indentation/"
8631a2
+  else
8631a2
+    if [ -z "${prepare_boot_cache}" ]; then
8631a2
+      prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | grub_add_tab)"
8631a2
+    fi
8631a2
+    printf '%s\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/"
8631a2
+  fi
8631a2
+  sed "s/^/$submenu_indentation/" << EOF
8631a2
+	linux	${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args}
8631a2
+EOF
8631a2
+  if test -n "${initrd}" ; then
8631a2
+    initrd_path=
8631a2
+    for i in ${initrd}; do
8631a2
+      initrd_path="${initrd_path} ${rel_dirname}/${i}"
8631a2
+    done
8631a2
+    sed "s/^/$submenu_indentation/" << EOF
8631a2
+	initrd	$(echo $initrd_path)
8631a2
+EOF
8631a2
+  fi
8631a2
+  if test -n "${fdt}" ; then
8631a2
+    sed "s/^/$submenu_indentation/" << EOF
8631a2
+	devicetree	${rel_dirname}/${fdt}
8631a2
+EOF
8631a2
+  fi
8631a2
+  sed "s/^/$submenu_indentation/" << EOF
8631a2
+}
8631a2
+EOF
8631a2
+}
8631a2
+
8631a2
+machine=`uname -m`
8631a2
+case "x$machine" in
8631a2
+    xi?86 | xx86_64)
8631a2
+	list=
8631a2
+	for i in /boot/vmlinuz-* /vmlinuz-* /boot/kernel-* ; do
8631a2
+	    if grub_file_is_not_garbage "$i" ; then list="$list $i" ; fi
8631a2
+	done ;;
8631a2
+    *)
8631a2
+	list=
8631a2
+	for i in /boot/vmlinuz-* /boot/vmlinux-* /vmlinuz-* /vmlinux-* /boot/kernel-* ; do
8631a2
+                  if grub_file_is_not_garbage "$i" ; then list="$list $i" ; fi
8631a2
+	done ;;
8631a2
+esac
8631a2
+
8631a2
+if [ "x${GRUB_ENABLE_BLSCFG}" = "xtrue" ]; then
8631a2
+    for i in /boot/ostree/*/vmlinuz-* ; do
8631a2
+        if grub_file_is_not_garbage "$i" ; then list="$list $i" ; fi
8631a2
+    done
8631a2
+fi
8631a2
+
8631a2
+case "$machine" in
8631a2
+    i?86) GENKERNEL_ARCH="x86" ;;
8631a2
+    mips|mips64) GENKERNEL_ARCH="mips" ;;
8631a2
+    mipsel|mips64el) GENKERNEL_ARCH="mipsel" ;;
8631a2
+    arm*) GENKERNEL_ARCH="arm" ;;
8631a2
+    *) GENKERNEL_ARCH="$machine" ;;
8631a2
+esac
8631a2
+
8631a2
+prepare_boot_cache=
8631a2
+prepare_root_cache=
8631a2
+boot_device_id=
8631a2
+title_correction_code=
8631a2
+
8631a2
+# Extra indentation to add to menu entries in a submenu. We're not in a submenu
8631a2
+# yet, so it's empty. In a submenu it will be equal to '\t' (one tab).
8631a2
+submenu_indentation=""
8631a2
+
8631a2
+is_top_level=true
8631a2
+while [ "x$list" != "x" ] ; do
8631a2
+  linux=`version_find_latest $list`
8631a2
+  if [ "x${GRUB_ENABLE_BLSCFG}" != "xtrue" ]; then
8631a2
+    gettext_printf "Found linux image: %s\n" "$linux" >&2
8631a2
+  fi
8631a2
+
8631a2
+  basename=`basename $linux`
8631a2
+  dirname=`dirname $linux`
8631a2
+  rel_dirname=`make_system_path_relative_to_its_root $dirname`
8631a2
+  version=`echo $basename | sed -e "s,^[^0-9]*-,,g"`
8631a2
+  alt_version=`echo $version | sed -e "s,\.old$,,g"`
8631a2
+  linux_root_device_thisversion="${LINUX_ROOT_DEVICE}"
8631a2
+
8631a2
+  initrd_early=
8631a2
+  for i in ${GRUB_EARLY_INITRD_LINUX_STOCK} \
8631a2
+	   ${GRUB_EARLY_INITRD_LINUX_CUSTOM}; do
8631a2
+    if test -e "${dirname}/${i}" ; then
8631a2
+      initrd_early="${initrd_early} ${i}"
8631a2
+    fi
8631a2
+  done
8631a2
+
8631a2
+  initrd_real=
8631a2
+  for i in "initrd.img-${version}" "initrd-${version}.img" "initrd-${version}.gz" \
8631a2
+	   "initrd-${version}" "initramfs-${version}.img" \
8631a2
+	   "initrd.img-${alt_version}" "initrd-${alt_version}.img" \
8631a2
+	   "initrd-${alt_version}" "initramfs-${alt_version}.img" \
8631a2
+	   "initramfs-genkernel-${version}" \
8631a2
+	   "initramfs-genkernel-${alt_version}" \
8631a2
+	   "initramfs-genkernel-${GENKERNEL_ARCH}-${version}" \
8631a2
+	   "initramfs-genkernel-${GENKERNEL_ARCH}-${alt_version}"; do
8631a2
+    if test -e "${dirname}/${i}" ; then
8631a2
+      initrd_real="${i}"
8631a2
+      break
8631a2
+    fi
8631a2
+  done
8631a2
+
8631a2
+  initrd=
8631a2
+  if test -n "${initrd_early}" || test -n "${initrd_real}"; then
8631a2
+    initrd="${initrd_early} ${initrd_real}"
8631a2
+
8631a2
+    initrd_display=
8631a2
+    for i in ${initrd}; do
8631a2
+      initrd_display="${initrd_display} ${dirname}/${i}"
8631a2
+    done
8631a2
+    if [ "x${GRUB_ENABLE_BLSCFG}" != "xtrue" ]; then
8631a2
+      gettext_printf "Found initrd image: %s\n" "$(echo $initrd_display)" >&2
8631a2
+    fi
8631a2
+  fi
8631a2
+
8631a2
+  fdt=
8631a2
+  for i in "dtb-${version}" "dtb-${alt_version}"; do
8631a2
+    if test -f "${dirname}/${i}/${GRUB_DEFAULT_DTB}" ; then
8631a2
+      fdt="${i}/${GRUB_DEFAULT_DTB}"
8631a2
+      break
8631a2
+    fi
8631a2
+  done
8631a2
+
8631a2
+  config=
8631a2
+  for i in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do
8631a2
+    if test -e "${i}" ; then
8631a2
+      config="${i}"
8631a2
+      break
8631a2
+    fi
8631a2
+  done
8631a2
+
8631a2
+  initramfs=
8631a2
+  if test -n "${config}" ; then
8631a2
+      initramfs=`grep CONFIG_INITRAMFS_SOURCE= "${config}" | cut -f2 -d= | tr -d \"`
8631a2
+  fi
8631a2
+
8631a2
+  if test -z "${initramfs}" && test -z "${initrd_real}" ; then
8631a2
+    # "UUID=" and "ZFS=" magic is parsed by initrd or initramfs.  Since there's
8631a2
+    # no initrd or builtin initramfs, it can't work here.
8631a2
+    if [ "x${GRUB_DEVICE_PARTUUID}" = "x" ] \
8631a2
+	|| [ "x${GRUB_DISABLE_LINUX_PARTUUID}" = "xtrue" ]; then
8631a2
+
8631a2
+	linux_root_device_thisversion=${GRUB_DEVICE}
8631a2
+    else
8631a2
+	linux_root_device_thisversion=PARTUUID=${GRUB_DEVICE_PARTUUID}
8631a2
+    fi
8631a2
+  fi
8631a2
+
8631a2
+  if [ "x${GRUB_DISABLE_SUBMENU}" = "xyes" ] || [ "x${GRUB_DISABLE_SUBMENU}" = "xy" ]; then
8631a2
+    GRUB_DISABLE_SUBMENU="true"
8631a2
+  fi
8631a2
+
8631a2
+  if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xtrue ]; then
8631a2
+    linux_entry "${OS}" "${version}" simple standard \
8631a2
+    "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
8631a2
+    if [ "x$GRUB_LINUX_MAKE_DEBUG" = "xtrue" ]; then
8631a2
+      linux_entry "${OS}" "${version}" simple debug \
8631a2
+        "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT} ${GRUB_CMDLINE_LINUX_DEBUG}"
8631a2
+    fi
8631a2
+
8631a2
+    submenu_indentation="$grub_tab"
8631a2
+
8631a2
+    if [ -z "$boot_device_id" ]; then
8631a2
+	boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
8631a2
+    fi
8631a2
+    # TRANSLATORS: %s is replaced with an OS name
8631a2
+    echo "submenu '$(gettext_printf "Advanced options for %s" "${OS}" | grub_quote)' \$menuentry_id_option 'gnulinux-advanced-$boot_device_id' {"
8631a2
+    is_top_level=false
8631a2
+  fi
8631a2
+
8631a2
+  linux_entry "${OS}" "${version}" advanced standard \
8631a2
+              "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
8631a2
+  if [ "x$GRUB_LINUX_MAKE_DEBUG" = "xtrue" ]; then
8631a2
+    linux_entry "${OS}" "${version}" advanced debug \
8631a2
+                "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT} ${GRUB_CMDLINE_LINUX_DEBUG}"
8631a2
+  fi
8631a2
+
8631a2
+  if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
8631a2
+    linux_entry "${OS}" "${version}" recovery standard \
8631a2
+                "single ${GRUB_CMDLINE_LINUX}"
8631a2
+  fi
8631a2
+
8631a2
+  list=`echo $list | tr ' ' '\n' | fgrep -vx "$linux" | tr '\n' ' '`
8631a2
+done
8631a2
+
8631a2
+# If at least one kernel was found, then we need to
8631a2
+# add a closing '}' for the submenu command.
8631a2
+if [ x"$is_top_level" != xtrue ]; then
8631a2
+  echo '}'
8631a2
+fi
8631a2
+
8631a2
+echo "$title_correction_code"