grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[RESEND RESEND PATCH] templates: introduce GRUB_TOP_LEVEL_* vars


From: Denton Liu
Subject: [RESEND RESEND PATCH] templates: introduce GRUB_TOP_LEVEL_* vars
Date: Wed, 21 Sep 2022 04:22:25 -0700

A user may wish to use an image that is not sorted as the "latest"
version as the top-level entry. For example, in Arch Linux, if a user
has the LTS and regular kernels installed, `/boot/vmlinuz-linux-lts`
gets sorted as the "latest" compared to `/boot/vmlinuz-linux`. However,
a user may wish to use the regular kernel as the default with the LTS
only existing as a backup.

Introduce the GRUB_TOP_LEVEL_LINUX and GRUB_TOP_LEVEL_XEN variables to
allow users to specify the top-level entry.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 docs/grub.texi              |  5 +++++
 util/grub-mkconfig.in       |  2 ++
 util/grub-mkconfig_lib.in   | 21 +++++++++++++++++++++
 util/grub.d/10_linux.in     |  4 ++++
 util/grub.d/20_linux_xen.in |  7 +++++++
 5 files changed, 39 insertions(+)

diff --git a/docs/grub.texi b/docs/grub.texi
index 107f66ebc..54bd32882 100644
--- a/docs/grub.texi
+++ b/docs/grub.texi
@@ -1444,6 +1444,11 @@ for all respectively normal entries.
 The values of these options replace the values of @samp{GRUB_CMDLINE_LINUX}
 and @samp{GRUB_CMDLINE_LINUX_DEFAULT} for Linux and Xen menu entries.
 
+@item GRUB_TOP_LEVEL_LINUX
+@item GRUB_TOP_LEVEL_XEN
+If this option is provided, the given image file will be made the top-level
+entry if the image file is found in the scan.
+
 @item GRUB_EARLY_INITRD_LINUX_CUSTOM
 @itemx GRUB_EARLY_INITRD_LINUX_STOCK
 List of space-separated early initrd images to be loaded from @samp{/boot}.
diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in
index 62335d027..f7ad160b4 100644
--- a/util/grub-mkconfig.in
+++ b/util/grub-mkconfig.in
@@ -233,6 +233,8 @@ export GRUB_DEFAULT \
   GRUB_CMDLINE_NETBSD \
   GRUB_CMDLINE_NETBSD_DEFAULT \
   GRUB_CMDLINE_GNUMACH \
+  GRUB_TOP_LEVEL_LINUX \
+  GRUB_TOP_LEVEL_XEN \
   GRUB_EARLY_INITRD_LINUX_CUSTOM \
   GRUB_EARLY_INITRD_LINUX_STOCK \
   GRUB_TERMINAL_INPUT \
diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in
index 634bc8a50..5be49a07c 100644
--- a/util/grub-mkconfig_lib.in
+++ b/util/grub-mkconfig_lib.in
@@ -218,6 +218,27 @@ version_sort ()
    esac
 }
 
+grub_move_entry_to_front ()
+{
+  entry="$1"
+  shift
+
+  entry_found=false
+  for i in "$@"; do
+    if [ "x$i" = "x$entry" ]; then
+      entry_found=true
+    fi
+  done
+
+  if [ "x$entry_found" = xtrue ]; then
+    echo "$entry"
+  fi
+  for i in "$@"; do
+    if [ "x$i" = "x$entry" ]; then continue; fi
+    echo "$i"
+  done
+}
+
 # One layer of quotation is eaten by "" and the second by sed; so this turns
 # ' into \'.
 grub_quote () {
diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in
index c6a1ec935..05e01fc85 100644
--- a/util/grub.d/10_linux.in
+++ b/util/grub.d/10_linux.in
@@ -202,6 +202,10 @@ submenu_indentation=""
 
 reverse_sorted_list=$(echo $list | tr ' ' '\n' | sed -e 's/\.old$/ 1/; / 1$/! 
s/$/ 2/' | version_sort -r | sed -e 's/ 1$/.old/; s/ 2$//')
 
+if [ "x$GRUB_TOP_LEVEL_LINUX" != x ]; then
+  reverse_sorted_list=$(grub_move_entry_to_front "$GRUB_TOP_LEVEL_LINUX" 
${reverse_sorted_list})
+fi
+
 is_top_level=true
 for linux in ${reverse_sorted_list}; do
   gettext_printf "Found linux image: %s\n" "$linux" >&2
diff --git a/util/grub.d/20_linux_xen.in b/util/grub.d/20_linux_xen.in
index 626aed40c..c32bb979f 100644
--- a/util/grub.d/20_linux_xen.in
+++ b/util/grub.d/20_linux_xen.in
@@ -245,6 +245,13 @@ submenu_indentation=""
 reverse_sorted_xen_list=$(echo ${xen_list} | tr ' ' '\n' | sed -e 's/\.old$/ 
1/; / 1$/! s/$/ 2/' | version_sort -r | sed -e 's/ 1$/.old/; s/ 2$//')
 reverse_sorted_linux_list=$(echo ${linux_list} | tr ' ' '\n' | sed -e 
's/\.old$/ 1/; / 1$/! s/$/ 2/' | version_sort -r | sed -e 's/ 1$/.old/; s/ 
2$//')
 
+if [ "x$GRUB_TOP_LEVEL_XEN" != x ]; then
+  reverse_sorted_xen_list=$(grub_move_entry_to_front "$GRUB_TOP_LEVEL_XEN" 
${reverse_sorted_xen_list})
+fi
+if [ "x$GRUB_TOP_LEVEL_LINUX" != x ]; then
+  reverse_sorted_linux_list=$(grub_move_entry_to_front "$GRUB_TOP_LEVEL_LINUX" 
${reverse_sorted_linux_list})
+fi
+
 is_top_level=true
 
 for current_xen in ${reverse_sorted_xen_list}; do
-- 
2.37.3




reply via email to

[Prev in Thread] Current Thread [Next in Thread]