All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] templates: introduce GRUB_TOP_LEVEL_* vars
@ 2022-08-21 10:24 Denton Liu
  2022-08-29  6:11 ` [RESEND PATCH] " Denton Liu
  2022-09-30 11:11 ` [PATCH v2] " Denton Liu
  0 siblings, 2 replies; 13+ messages in thread
From: Denton Liu @ 2022-08-21 10:24 UTC (permalink / raw)
  To: grub-devel

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.2



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [RESEND PATCH] templates: introduce GRUB_TOP_LEVEL_* vars
  2022-08-21 10:24 [PATCH] templates: introduce GRUB_TOP_LEVEL_* vars Denton Liu
@ 2022-08-29  6:11 ` Denton Liu
  2022-09-21 11:22   ` [RESEND RESEND " Denton Liu
  2022-09-30 11:11 ` [PATCH v2] " Denton Liu
  1 sibling, 1 reply; 13+ messages in thread
From: Denton Liu @ 2022-08-29  6:11 UTC (permalink / raw)
  To: grub-devel

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.2



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [RESEND RESEND PATCH] templates: introduce GRUB_TOP_LEVEL_* vars
  2022-08-29  6:11 ` [RESEND PATCH] " Denton Liu
@ 2022-09-21 11:22   ` Denton Liu
  2022-09-27 12:30     ` [RESEND RESEND " Denton Liu
  0 siblings, 1 reply; 13+ messages in thread
From: Denton Liu @ 2022-09-21 11:22 UTC (permalink / raw)
  To: grub-devel

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



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [RESEND RESEND RESEND PATCH] templates: introduce GRUB_TOP_LEVEL_* vars
  2022-09-21 11:22   ` [RESEND RESEND " Denton Liu
@ 2022-09-27 12:30     ` Denton Liu
  2022-09-29  6:08       ` Oskari Pirhonen
  0 siblings, 1 reply; 13+ messages in thread
From: Denton Liu @ 2022-09-27 12:30 UTC (permalink / raw)
  To: grub-devel; +Cc: Daniel Kiper

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



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [RESEND RESEND RESEND PATCH] templates: introduce GRUB_TOP_LEVEL_* vars
  2022-09-27 12:30     ` [RESEND RESEND " Denton Liu
@ 2022-09-29  6:08       ` Oskari Pirhonen
  2022-09-29 10:23         ` Denton Liu
  0 siblings, 1 reply; 13+ messages in thread
From: Oskari Pirhonen @ 2022-09-29  6:08 UTC (permalink / raw)
  To: The development of GNU GRUB; +Cc: Daniel Kiper, Denton Liu

[-- Attachment #1: Type: text/plain, Size: 1084 bytes --]

On Tue, Sep 27, 2022 at 05:30:45 -0700, Denton Liu wrote:
> 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.
> 

A couple questions:

- If all you're looking for is /boot/vmlinuz-linux to be booted, is
  setting GRUB_DEFAULT in /etc/default/grub "good enough" for your use
  case?
- Is it possible to make this solution more universal? Maybe BSD users
  would like to set their top level entry.
- What about for os-prober? My understanding is that it creates its own
  top level entries as well.

Note with the 1st question: I'm not saying GRUB_TOP_LEVEL_* is a bad
idea. I'm just curious.

- Oskari

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [RESEND RESEND RESEND PATCH] templates: introduce GRUB_TOP_LEVEL_* vars
  2022-09-29  6:08       ` Oskari Pirhonen
@ 2022-09-29 10:23         ` Denton Liu
  2022-09-30  6:53           ` Oskari Pirhonen
  0 siblings, 1 reply; 13+ messages in thread
From: Denton Liu @ 2022-09-29 10:23 UTC (permalink / raw)
  To: The development of GNU GRUB, Daniel Kiper

Thanks for the response, Oskari!

On Thu, Sep 29, 2022 at 01:08:03AM -0500, Oskari Pirhonen wrote:
> On Tue, Sep 27, 2022 at 05:30:45 -0700, Denton Liu wrote:
> > 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.
> > 
> 
> A couple questions:
> 
> - If all you're looking for is /boot/vmlinuz-linux to be booted, is
>   setting GRUB_DEFAULT in /etc/default/grub "good enough" for your use
>   case?

I think it is "good enough" for what I need but it feels a little bit
weird that grub doesn't give the user any choice as to what the
top-level kernel is.

> - Is it possible to make this solution more universal? Maybe BSD users
>   would like to set their top level entry.

I'm not too familiar with what end-users might want. If we want to make
this more universal, we could either do GRUB_TOP_LEVEL_KERNEL and have
that shared amongst all of the 10_* files or we could have multiple
variables, e.g. GRUB_TOP_LEVEL_LINUX, GRUB_TOP_LEVEL_BSD, etc.

> - What about for os-prober? My understanding is that it creates its own
>   top level entries as well.

The same thing could work with os-prober, although it wouldn't be a
cut-and-paste.

I'm open to all ideas here and I can cook up the patches. The thing is
that I'm not sure what the project's conventions are regarding
too-granular/not-granular-enough configurations so some advice here
would be very much appreciated!

-Denton


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [RESEND RESEND RESEND PATCH] templates: introduce GRUB_TOP_LEVEL_* vars
  2022-09-29 10:23         ` Denton Liu
@ 2022-09-30  6:53           ` Oskari Pirhonen
  2022-09-30 11:06             ` Denton Liu
  0 siblings, 1 reply; 13+ messages in thread
From: Oskari Pirhonen @ 2022-09-30  6:53 UTC (permalink / raw)
  To: The development of GNU GRUB; +Cc: Daniel Kiper, Denton Liu

[-- Attachment #1: Type: text/plain, Size: 2506 bytes --]

On Thu, Sep 29, 2022 at 03:23:07 -0700, Denton Liu wrote:
> Thanks for the response, Oskari!
> 
> On Thu, Sep 29, 2022 at 01:08:03AM -0500, Oskari Pirhonen wrote:
> > On Tue, Sep 27, 2022 at 05:30:45 -0700, Denton Liu wrote:
> > > 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.
> > > 
> > 
> > A couple questions:
> > 
> > - If all you're looking for is /boot/vmlinuz-linux to be booted, is
> >   setting GRUB_DEFAULT in /etc/default/grub "good enough" for your use
> >   case?
> 
> I think it is "good enough" for what I need but it feels a little bit
> weird that grub doesn't give the user any choice as to what the
> top-level kernel is.
> 

Perhaps no one has felt the need up until now ;)

> > - Is it possible to make this solution more universal? Maybe BSD users
> >   would like to set their top level entry.
> 
> I'm not too familiar with what end-users might want. If we want to make
> this more universal, we could either do GRUB_TOP_LEVEL_KERNEL and have
> that shared amongst all of the 10_* files or we could have multiple
> variables, e.g. GRUB_TOP_LEVEL_LINUX, GRUB_TOP_LEVEL_BSD, etc.
> 

A single GRUB_TOP_LEVEL or something is what I was thinking. I'm not
familiar with Xen, but based on your original patch, it may warrant its
own.

> > - What about for os-prober? My understanding is that it creates its own
> >   top level entries as well.
> 
> The same thing could work with os-prober, although it wouldn't be a
> cut-and-paste.
> 

os-prober would probably have its own GRUB_TOP_LEVEL_OS_PROBER or
something as well.

> I'm open to all ideas here and I can cook up the patches. The thing is
> that I'm not sure what the project's conventions are regarding
> too-granular/not-granular-enough configurations so some advice here
> would be very much appreciated!
> 

Generating a config for multiple OS's would use os-prober, so a single
"main" variable for top level entries would be simpler and should be
enough IMO.

- Oskari

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [RESEND RESEND RESEND PATCH] templates: introduce GRUB_TOP_LEVEL_* vars
  2022-09-30  6:53           ` Oskari Pirhonen
@ 2022-09-30 11:06             ` Denton Liu
  0 siblings, 0 replies; 13+ messages in thread
From: Denton Liu @ 2022-09-30 11:06 UTC (permalink / raw)
  To: Oskari Pirhonen; +Cc: The development of GNU GRUB, Daniel Kiper

Hi Oskari,

On Fri, Sep 30, 2022 at 01:53:59AM -0500, Oskari Pirhonen wrote:
> > I'm not too familiar with what end-users might want. If we want to make
> > this more universal, we could either do GRUB_TOP_LEVEL_KERNEL and have
> > that shared amongst all of the 10_* files or we could have multiple
> > variables, e.g. GRUB_TOP_LEVEL_LINUX, GRUB_TOP_LEVEL_BSD, etc.
> > 
> 
> A single GRUB_TOP_LEVEL or something is what I was thinking. I'm not
> familiar with Xen, but based on your original patch, it may warrant its
> own.

I'm not familiar with Xen either. My understanding is that there can be
parallel top-level entries so it deserves its own variable.

> > > - What about for os-prober? My understanding is that it creates its own
> > >   top level entries as well.
> > 
> > The same thing could work with os-prober, although it wouldn't be a
> > cut-and-paste.
> > 
> 
> os-prober would probably have its own GRUB_TOP_LEVEL_OS_PROBER or
> something as well.

Sounds good!

> > I'm open to all ideas here and I can cook up the patches. The thing is
> > that I'm not sure what the project's conventions are regarding
> > too-granular/not-granular-enough configurations so some advice here
> > would be very much appreciated!
> > 
> 
> Generating a config for multiple OS's would use os-prober, so a single
> "main" variable for top level entries would be simpler and should be
> enough IMO.

Thanks for the feedback! Patch coming soon.

-Denton


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v2] templates: introduce GRUB_TOP_LEVEL_* vars
  2022-08-21 10:24 [PATCH] templates: introduce GRUB_TOP_LEVEL_* vars Denton Liu
  2022-08-29  6:11 ` [RESEND PATCH] " Denton Liu
@ 2022-09-30 11:11 ` Denton Liu
  2022-10-02  3:50   ` Oskari Pirhonen
  2022-10-05  9:22   ` [PATCH v3] " Denton Liu
  1 sibling, 2 replies; 13+ messages in thread
From: Denton Liu @ 2022-09-30 11:11 UTC (permalink / raw)
  To: grub-devel; +Cc: Daniel Kiper, Oskari Pirhonen

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, GRUB_TOP_LEVEL_XEN and
GRUB_TOP_LEVEL_OS_PROBER variables to allow users to specify the
top-level entry.

The only file that was tested is 10_linux. I do not have access to any
of the other images or systems so they remain untested.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 docs/grub.texi              |  6 ++++++
 util/grub-mkconfig.in       |  3 +++
 util/grub-mkconfig_lib.in   | 21 +++++++++++++++++++++
 util/grub.d/10_hurd.in      |  4 ++++
 util/grub.d/10_kfreebsd.in  |  4 ++++
 util/grub.d/10_linux.in     |  4 ++++
 util/grub.d/10_netbsd.in    | 10 +++++++++-
 util/grub.d/20_linux_xen.in |  7 +++++++
 util/grub.d/30_os-prober.in |  4 ++++
 9 files changed, 62 insertions(+), 1 deletion(-)

diff --git a/docs/grub.texi b/docs/grub.texi
index 107f66ebc..16a445178 100644
--- a/docs/grub.texi
+++ b/docs/grub.texi
@@ -1444,6 +1444,12 @@ 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
+@item GRUB_TOP_LEVEL_XEN
+@item GRUB_TOP_LEVEL_OS_PROBER
+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..32c480dae 100644
--- a/util/grub-mkconfig.in
+++ b/util/grub-mkconfig.in
@@ -233,6 +233,9 @@ export GRUB_DEFAULT \
   GRUB_CMDLINE_NETBSD \
   GRUB_CMDLINE_NETBSD_DEFAULT \
   GRUB_CMDLINE_GNUMACH \
+  GRUB_TOP_LEVEL \
+  GRUB_TOP_LEVEL_XEN \
+  GRUB_TOP_LEVEL_OS_PROBER \
   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_hurd.in b/util/grub.d/10_hurd.in
index 4294bbe4c..0ae5a3927 100644
--- a/util/grub.d/10_hurd.in
+++ b/util/grub.d/10_hurd.in
@@ -205,6 +205,10 @@ submenu_indentation=""
 
 reverse_sorted_kernels=$(echo ${kernels} | 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" != x ]; then
+  reverse_sorted_kernels=$(grub_move_entry_to_front "$GRUB_TOP_LEVEL" ${reverse_sorted_kernels})
+fi
+
 is_top_level=true
 
 for kernel in ${reverse_sorted_kernels}; do
diff --git a/util/grub.d/10_kfreebsd.in b/util/grub.d/10_kfreebsd.in
index 0a67decaa..506b2df66 100644
--- a/util/grub.d/10_kfreebsd.in
+++ b/util/grub.d/10_kfreebsd.in
@@ -164,6 +164,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" != x ]; then
+  reverse_sorted_list=$(grub_move_entry_to_front "$GRUB_TOP_LEVEL" ${reverse_sorted_list})
+fi
+
 is_top_level=true
 
 for kfreebsd in ${reverse_sorted_list}; do
diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in
index c6a1ec935..a479c16af 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" != x ]; then
+  reverse_sorted_list=$(grub_move_entry_to_front "$GRUB_TOP_LEVEL" ${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/10_netbsd.in b/util/grub.d/10_netbsd.in
index dc0cd1b17..4eae58e82 100644
--- a/util/grub.d/10_netbsd.in
+++ b/util/grub.d/10_netbsd.in
@@ -147,10 +147,18 @@ pattern="^ELF[^,]*executable.*statically linked"
 submenu_indentation=""
 
 is_top_level=true
-for k in /netbsd $(ls -t /netbsd?* 2>/dev/null) ; do
+grub_top_level_found=false
+for k in "$GRUB_TOP_LEVEL" /netbsd $(ls -t /netbsd?* 2>/dev/null) ; do
   if ! grub_file_is_not_garbage "$k" ; then
     continue
   fi
+  if [ "x$GRUB_TOP_LEVEL" = "x$k" ] ; then
+    if [ "x$grub_top_level_found" = xfalse ] ; then
+      grub_top_level_found=true
+    else
+      continue
+    fi
+  fi
   if ! (zcat -f "$k" | file -bL - | grep -q "${pattern}") 2>/dev/null ; then
     continue
   fi
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
diff --git a/util/grub.d/30_os-prober.in b/util/grub.d/30_os-prober.in
index daa603778..9b2a96bd0 100644
--- a/util/grub.d/30_os-prober.in
+++ b/util/grub.d/30_os-prober.in
@@ -113,6 +113,10 @@ EOF
 
 used_osprober_linux_ids=
 
+if [ "x$GRUB_TOP_LEVEL_OS_PROBER" != x ]; then
+  OSPROBED=$(grub_move_entry_to_front "$GRUB_TOP_LEVEL_OS_PROBER" ${OSPROBED})
+fi
+
 for OS in ${OSPROBED} ; do
   DEVICE="`echo ${OS} | cut -d ':' -f 1`"
   LONGNAME="`echo ${OS} | cut -d ':' -f 2 | tr '^' ' '`"
-- 
2.37.3



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH v2] templates: introduce GRUB_TOP_LEVEL_* vars
  2022-09-30 11:11 ` [PATCH v2] " Denton Liu
@ 2022-10-02  3:50   ` Oskari Pirhonen
  2022-10-05  9:22   ` [PATCH v3] " Denton Liu
  1 sibling, 0 replies; 13+ messages in thread
From: Oskari Pirhonen @ 2022-10-02  3:50 UTC (permalink / raw)
  To: grub-devel; +Cc: Daniel Kiper, Denton Liu

[-- Attachment #1: Type: text/plain, Size: 8789 bytes --]

On Fri, Sep 30, 2022 at 04:11:11 -0700, Denton Liu wrote:
> 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, GRUB_TOP_LEVEL_XEN and
> GRUB_TOP_LEVEL_OS_PROBER variables to allow users to specify the
> top-level entry.


> 
> The only file that was tested is 10_linux. I do not have access to any
> of the other images or systems so they remain untested.
> 

Blurbs like this should be placed below the "---" line so they don't
show up in commit messages. A brief changelog summarizing the
differences between patch versions is also nice (and belongs under the
"---" as well) so readers don't have to hunt for the previous versions
and analyze them to get an idea of the evolution of the patch. Bullet
points is generally enough for this.

> Signed-off-by: Denton Liu <liu.denton@gmail.com>
> ---

(Example changelog)
v3:
- changes between v2 and v3
- ...

v2:
- use a more generic GRUB_TOP_LEVEL
- ...

>  docs/grub.texi              |  6 ++++++
>  util/grub-mkconfig.in       |  3 +++
>  util/grub-mkconfig_lib.in   | 21 +++++++++++++++++++++
>  util/grub.d/10_hurd.in      |  4 ++++
>  util/grub.d/10_kfreebsd.in  |  4 ++++
>  util/grub.d/10_linux.in     |  4 ++++
>  util/grub.d/10_netbsd.in    | 10 +++++++++-
>  util/grub.d/20_linux_xen.in |  7 +++++++
>  util/grub.d/30_os-prober.in |  4 ++++
>  9 files changed, 62 insertions(+), 1 deletion(-)
> 
> diff --git a/docs/grub.texi b/docs/grub.texi
> index 107f66ebc..16a445178 100644
> --- a/docs/grub.texi
> +++ b/docs/grub.texi
> @@ -1444,6 +1444,12 @@ 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
> +@item GRUB_TOP_LEVEL_XEN
> +@item GRUB_TOP_LEVEL_OS_PROBER
> +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.

I think explicitly mentioning that it's a _kernel_ image would be good.
That way no one can complain when their cute_cat.png wasn't made into a
top level entry. Also worth noting that you need to specify the path to
the kernel, not just the file name.

> +
>  @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..32c480dae 100644
> --- a/util/grub-mkconfig.in
> +++ b/util/grub-mkconfig.in
> @@ -233,6 +233,9 @@ export GRUB_DEFAULT \
>    GRUB_CMDLINE_NETBSD \
>    GRUB_CMDLINE_NETBSD_DEFAULT \
>    GRUB_CMDLINE_GNUMACH \
> +  GRUB_TOP_LEVEL \
> +  GRUB_TOP_LEVEL_XEN \
> +  GRUB_TOP_LEVEL_OS_PROBER \
>    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 ()

I think a better name would be just `grub_move_to_front`. It makes it
more clear that this function can be used for more than just menu
entries in case someone wants to use it for something else in the
future. A short comment describing the arguments would be helpful for
that too.

Mention of this function is completely missing from the commit message.

> +{
> +  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_hurd.in b/util/grub.d/10_hurd.in
> index 4294bbe4c..0ae5a3927 100644
> --- a/util/grub.d/10_hurd.in
> +++ b/util/grub.d/10_hurd.in
> @@ -205,6 +205,10 @@ submenu_indentation=""
>  
>  reverse_sorted_kernels=$(echo ${kernels} | 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" != x ]; then
> +  reverse_sorted_kernels=$(grub_move_entry_to_front "$GRUB_TOP_LEVEL" ${reverse_sorted_kernels})
> +fi
> +
>  is_top_level=true
>  
>  for kernel in ${reverse_sorted_kernels}; do
> diff --git a/util/grub.d/10_kfreebsd.in b/util/grub.d/10_kfreebsd.in
> index 0a67decaa..506b2df66 100644
> --- a/util/grub.d/10_kfreebsd.in
> +++ b/util/grub.d/10_kfreebsd.in
> @@ -164,6 +164,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" != x ]; then
> +  reverse_sorted_list=$(grub_move_entry_to_front "$GRUB_TOP_LEVEL" ${reverse_sorted_list})
> +fi
> +
>  is_top_level=true
>  
>  for kfreebsd in ${reverse_sorted_list}; do
> diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in
> index c6a1ec935..a479c16af 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" != x ]; then
> +  reverse_sorted_list=$(grub_move_entry_to_front "$GRUB_TOP_LEVEL" ${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/10_netbsd.in b/util/grub.d/10_netbsd.in
> index dc0cd1b17..4eae58e82 100644
> --- a/util/grub.d/10_netbsd.in
> +++ b/util/grub.d/10_netbsd.in
> @@ -147,10 +147,18 @@ pattern="^ELF[^,]*executable.*statically linked"
>  submenu_indentation=""
>  
>  is_top_level=true
> -for k in /netbsd $(ls -t /netbsd?* 2>/dev/null) ; do
> +grub_top_level_found=false
> +for k in "$GRUB_TOP_LEVEL" /netbsd $(ls -t /netbsd?* 2>/dev/null) ; do
>    if ! grub_file_is_not_garbage "$k" ; then
>      continue
>    fi
> +  if [ "x$GRUB_TOP_LEVEL" = "x$k" ] ; then
> +    if [ "x$grub_top_level_found" = xfalse ] ; then
> +      grub_top_level_found=true
> +    else
> +      continue
> +    fi
> +  fi
>    if ! (zcat -f "$k" | file -bL - | grep -q "${pattern}") 2>/dev/null ; then
>      continue
>    fi
> 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

Here you've still got GRUB_TOP_LEVEL_LINUX but it's not documented
above. Is it meant to have its own, or did you just forget to replace it
with GRUB_TOP_LEVEL when going through them?

> +
>  is_top_level=true
>  
>  for current_xen in ${reverse_sorted_xen_list}; do
> diff --git a/util/grub.d/30_os-prober.in b/util/grub.d/30_os-prober.in
> index daa603778..9b2a96bd0 100644
> --- a/util/grub.d/30_os-prober.in
> +++ b/util/grub.d/30_os-prober.in
> @@ -113,6 +113,10 @@ EOF
>  
>  used_osprober_linux_ids=
>  
> +if [ "x$GRUB_TOP_LEVEL_OS_PROBER" != x ]; then
> +  OSPROBED=$(grub_move_entry_to_front "$GRUB_TOP_LEVEL_OS_PROBER" ${OSPROBED})
> +fi
> +
>  for OS in ${OSPROBED} ; do
>    DEVICE="`echo ${OS} | cut -d ':' -f 1`"
>    LONGNAME="`echo ${OS} | cut -d ':' -f 2 | tr '^' ' '`"
> -- 
> 2.37.3
> 

- Oskari

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v3] templates: introduce GRUB_TOP_LEVEL_* vars
  2022-09-30 11:11 ` [PATCH v2] " Denton Liu
  2022-10-02  3:50   ` Oskari Pirhonen
@ 2022-10-05  9:22   ` Denton Liu
  2022-10-07  5:08     ` Oskari Pirhonen
  2022-10-14 10:11     ` Daniel Kiper
  1 sibling, 2 replies; 13+ messages in thread
From: Denton Liu @ 2022-10-05  9:22 UTC (permalink / raw)
  To: grub-devel; +Cc: Daniel Kiper, Oskari Pirhonen

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, GRUB_TOP_LEVEL_XEN and
GRUB_TOP_LEVEL_OS_PROBER variables to allow users to specify the
top-level entry.

Create grub_move_to_front() as a helper function which moves entries to
the front of a list. This function does the heavy lifting of moving
the menu entry to the front in each script.

In 10_netbsd, since there isn't an explicit list variable, extract the
items that are being iterated through into a list so that we can
optionally apply grub_move_to_front() to the list before the loop.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---

Notes:
    The only file that was tested is 10_linux. I do not have access to any
    of the other images or systems so they remain untested.
    
    Changes since v2:
    
    * Added more detail to GRUB_TOP_LEVEL docs
    
    * Moved GRUB_TOP_LEVEL_OS_PROBER to separate section in docs
    
    * Renamed grub_move_entry_to_front() to grub_move_to_front() and added
      code comment
    
    * Give 10_netbsd an intermediate list of images to interact with

Interdiff against v2:
  diff --git a/docs/grub.texi b/docs/grub.texi
  index 16a445178..db6b20531 100644
  --- a/docs/grub.texi
  +++ b/docs/grub.texi
  @@ -1446,9 +1446,13 @@ and @samp{GRUB_CMDLINE_LINUX_DEFAULT} for Linux and Xen menu entries.
   
   @item GRUB_TOP_LEVEL
   @item GRUB_TOP_LEVEL_XEN
  +This option should be a path to a kernel image. If provided, the image
  +specified will be made the top-level entry if it is found in the scan.
  +
   @item GRUB_TOP_LEVEL_OS_PROBER
  -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.
  +This option should be a line of output from @command{os-prober}. As
  +@samp{GRUB_TOP_LEVEL}, if provided, the image specified will be made the
  +top-level entry if it is found in the scan.
   
   @item GRUB_EARLY_INITRD_LINUX_CUSTOM
   @itemx GRUB_EARLY_INITRD_LINUX_STOCK
  diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in
  index 5be49a07c..f4ae41f86 100644
  --- a/util/grub-mkconfig_lib.in
  +++ b/util/grub-mkconfig_lib.in
  @@ -218,23 +218,26 @@ version_sort ()
      esac
   }
   
  -grub_move_entry_to_front ()
  +# Given an item as the first argument and a list as the subsequent arguments,
  +# returns the list with the first argument moved to the front if it exists in
  +# the list.
  +grub_move_to_front ()
   {
  -  entry="$1"
  +  item="$1"
     shift
   
  -  entry_found=false
  +  item_found=false
     for i in "$@"; do
  -    if [ "x$i" = "x$entry" ]; then
  -      entry_found=true
  +    if [ "x$i" = "x$item" ]; then
  +      item_found=true
       fi
     done
   
  -  if [ "x$entry_found" = xtrue ]; then
  -    echo "$entry"
  +  if [ "x$item_found" = xtrue ]; then
  +    echo "$item"
     fi
     for i in "$@"; do
  -    if [ "x$i" = "x$entry" ]; then continue; fi
  +    if [ "x$i" = "x$item" ]; then continue; fi
       echo "$i"
     done
   }
  diff --git a/util/grub.d/10_hurd.in b/util/grub.d/10_hurd.in
  index 0ae5a3927..b7be7041c 100644
  --- a/util/grub.d/10_hurd.in
  +++ b/util/grub.d/10_hurd.in
  @@ -206,7 +206,7 @@ submenu_indentation=""
   reverse_sorted_kernels=$(echo ${kernels} | 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" != x ]; then
  -  reverse_sorted_kernels=$(grub_move_entry_to_front "$GRUB_TOP_LEVEL" ${reverse_sorted_kernels})
  +  reverse_sorted_kernels=$(grub_move_to_front "$GRUB_TOP_LEVEL" ${reverse_sorted_kernels})
   fi
   
   is_top_level=true
  diff --git a/util/grub.d/10_kfreebsd.in b/util/grub.d/10_kfreebsd.in
  index 506b2df66..83e9636e8 100644
  --- a/util/grub.d/10_kfreebsd.in
  +++ b/util/grub.d/10_kfreebsd.in
  @@ -165,7 +165,7 @@ 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" != x ]; then
  -  reverse_sorted_list=$(grub_move_entry_to_front "$GRUB_TOP_LEVEL" ${reverse_sorted_list})
  +  reverse_sorted_list=$(grub_move_to_front "$GRUB_TOP_LEVEL" ${reverse_sorted_list})
   fi
   
   is_top_level=true
  diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in
  index a479c16af..7263f2983 100644
  --- a/util/grub.d/10_linux.in
  +++ b/util/grub.d/10_linux.in
  @@ -203,7 +203,7 @@ 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" != x ]; then
  -  reverse_sorted_list=$(grub_move_entry_to_front "$GRUB_TOP_LEVEL" ${reverse_sorted_list})
  +  reverse_sorted_list=$(grub_move_to_front "$GRUB_TOP_LEVEL" ${reverse_sorted_list})
   fi
   
   is_top_level=true
  diff --git a/util/grub.d/10_netbsd.in b/util/grub.d/10_netbsd.in
  index 4eae58e82..3154e9e15 100644
  --- a/util/grub.d/10_netbsd.in
  +++ b/util/grub.d/10_netbsd.in
  @@ -146,19 +146,17 @@ pattern="^ELF[^,]*executable.*statically linked"
   # yet, so it's empty. In a submenu it will be equal to '\t' (one tab).
   submenu_indentation=""
   
  +list="/netbsd $(ls -t /netbsd?* 2>/dev/null)"
  +
  +if [ "x$GRUB_TOP_LEVEL" != x ]; then
  +  list=$(grub_move_to_front "$GRUB_TOP_LEVEL" ${list})
  +fi
  +
   is_top_level=true
  -grub_top_level_found=false
  -for k in "$GRUB_TOP_LEVEL" /netbsd $(ls -t /netbsd?* 2>/dev/null) ; do
  +for k in ${list}; do
     if ! grub_file_is_not_garbage "$k" ; then
       continue
     fi
  -  if [ "x$GRUB_TOP_LEVEL" = "x$k" ] ; then
  -    if [ "x$grub_top_level_found" = xfalse ] ; then
  -      grub_top_level_found=true
  -    else
  -      continue
  -    fi
  -  fi
     if ! (zcat -f "$k" | file -bL - | grep -q "${pattern}") 2>/dev/null ; then
       continue
     fi
  diff --git a/util/grub.d/20_linux_xen.in b/util/grub.d/20_linux_xen.in
  index c32bb979f..386bfb9be 100644
  --- a/util/grub.d/20_linux_xen.in
  +++ b/util/grub.d/20_linux_xen.in
  @@ -246,10 +246,10 @@ reverse_sorted_xen_list=$(echo ${xen_list} | tr ' ' '\n' | sed -e 's/\.old$/ 1/;
   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})
  +  reverse_sorted_xen_list=$(grub_move_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})
  +if [ "x$GRUB_TOP_LEVEL" != x ]; then
  +  reverse_sorted_linux_list=$(grub_move_to_front "$GRUB_TOP_LEVEL" ${reverse_sorted_linux_list})
   fi
   
   is_top_level=true
  diff --git a/util/grub.d/30_os-prober.in b/util/grub.d/30_os-prober.in
  index 9b2a96bd0..656301eaf 100644
  --- a/util/grub.d/30_os-prober.in
  +++ b/util/grub.d/30_os-prober.in
  @@ -114,7 +114,7 @@ EOF
   used_osprober_linux_ids=
   
   if [ "x$GRUB_TOP_LEVEL_OS_PROBER" != x ]; then
  -  OSPROBED=$(grub_move_entry_to_front "$GRUB_TOP_LEVEL_OS_PROBER" ${OSPROBED})
  +  OSPROBED=$(grub_move_to_front "$GRUB_TOP_LEVEL_OS_PROBER" ${OSPROBED})
   fi
   
   for OS in ${OSPROBED} ; do

 docs/grub.texi              | 10 ++++++++++
 util/grub-mkconfig.in       |  3 +++
 util/grub-mkconfig_lib.in   | 24 ++++++++++++++++++++++++
 util/grub.d/10_hurd.in      |  4 ++++
 util/grub.d/10_kfreebsd.in  |  4 ++++
 util/grub.d/10_linux.in     |  4 ++++
 util/grub.d/10_netbsd.in    |  8 +++++++-
 util/grub.d/20_linux_xen.in |  7 +++++++
 util/grub.d/30_os-prober.in |  4 ++++
 9 files changed, 67 insertions(+), 1 deletion(-)

diff --git a/docs/grub.texi b/docs/grub.texi
index 107f66ebc..db6b20531 100644
--- a/docs/grub.texi
+++ b/docs/grub.texi
@@ -1444,6 +1444,16 @@ 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
+@item GRUB_TOP_LEVEL_XEN
+This option should be a path to a kernel image. If provided, the image
+specified will be made the top-level entry if it is found in the scan.
+
+@item GRUB_TOP_LEVEL_OS_PROBER
+This option should be a line of output from @command{os-prober}. As
+@samp{GRUB_TOP_LEVEL}, if provided, the image specified will be made the
+top-level entry if it 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..32c480dae 100644
--- a/util/grub-mkconfig.in
+++ b/util/grub-mkconfig.in
@@ -233,6 +233,9 @@ export GRUB_DEFAULT \
   GRUB_CMDLINE_NETBSD \
   GRUB_CMDLINE_NETBSD_DEFAULT \
   GRUB_CMDLINE_GNUMACH \
+  GRUB_TOP_LEVEL \
+  GRUB_TOP_LEVEL_XEN \
+  GRUB_TOP_LEVEL_OS_PROBER \
   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..f4ae41f86 100644
--- a/util/grub-mkconfig_lib.in
+++ b/util/grub-mkconfig_lib.in
@@ -218,6 +218,30 @@ version_sort ()
    esac
 }
 
+# Given an item as the first argument and a list as the subsequent arguments,
+# returns the list with the first argument moved to the front if it exists in
+# the list.
+grub_move_to_front ()
+{
+  item="$1"
+  shift
+
+  item_found=false
+  for i in "$@"; do
+    if [ "x$i" = "x$item" ]; then
+      item_found=true
+    fi
+  done
+
+  if [ "x$item_found" = xtrue ]; then
+    echo "$item"
+  fi
+  for i in "$@"; do
+    if [ "x$i" = "x$item" ]; 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_hurd.in b/util/grub.d/10_hurd.in
index 4294bbe4c..b7be7041c 100644
--- a/util/grub.d/10_hurd.in
+++ b/util/grub.d/10_hurd.in
@@ -205,6 +205,10 @@ submenu_indentation=""
 
 reverse_sorted_kernels=$(echo ${kernels} | 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" != x ]; then
+  reverse_sorted_kernels=$(grub_move_to_front "$GRUB_TOP_LEVEL" ${reverse_sorted_kernels})
+fi
+
 is_top_level=true
 
 for kernel in ${reverse_sorted_kernels}; do
diff --git a/util/grub.d/10_kfreebsd.in b/util/grub.d/10_kfreebsd.in
index 0a67decaa..83e9636e8 100644
--- a/util/grub.d/10_kfreebsd.in
+++ b/util/grub.d/10_kfreebsd.in
@@ -164,6 +164,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" != x ]; then
+  reverse_sorted_list=$(grub_move_to_front "$GRUB_TOP_LEVEL" ${reverse_sorted_list})
+fi
+
 is_top_level=true
 
 for kfreebsd in ${reverse_sorted_list}; do
diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in
index c6a1ec935..7263f2983 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" != x ]; then
+  reverse_sorted_list=$(grub_move_to_front "$GRUB_TOP_LEVEL" ${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/10_netbsd.in b/util/grub.d/10_netbsd.in
index dc0cd1b17..3154e9e15 100644
--- a/util/grub.d/10_netbsd.in
+++ b/util/grub.d/10_netbsd.in
@@ -146,8 +146,14 @@ pattern="^ELF[^,]*executable.*statically linked"
 # yet, so it's empty. In a submenu it will be equal to '\t' (one tab).
 submenu_indentation=""
 
+list="/netbsd $(ls -t /netbsd?* 2>/dev/null)"
+
+if [ "x$GRUB_TOP_LEVEL" != x ]; then
+  list=$(grub_move_to_front "$GRUB_TOP_LEVEL" ${list})
+fi
+
 is_top_level=true
-for k in /netbsd $(ls -t /netbsd?* 2>/dev/null) ; do
+for k in ${list}; do
   if ! grub_file_is_not_garbage "$k" ; then
     continue
   fi
diff --git a/util/grub.d/20_linux_xen.in b/util/grub.d/20_linux_xen.in
index 626aed40c..386bfb9be 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_to_front "$GRUB_TOP_LEVEL_XEN" ${reverse_sorted_xen_list})
+fi
+if [ "x$GRUB_TOP_LEVEL" != x ]; then
+  reverse_sorted_linux_list=$(grub_move_to_front "$GRUB_TOP_LEVEL" ${reverse_sorted_linux_list})
+fi
+
 is_top_level=true
 
 for current_xen in ${reverse_sorted_xen_list}; do
diff --git a/util/grub.d/30_os-prober.in b/util/grub.d/30_os-prober.in
index daa603778..656301eaf 100644
--- a/util/grub.d/30_os-prober.in
+++ b/util/grub.d/30_os-prober.in
@@ -113,6 +113,10 @@ EOF
 
 used_osprober_linux_ids=
 
+if [ "x$GRUB_TOP_LEVEL_OS_PROBER" != x ]; then
+  OSPROBED=$(grub_move_to_front "$GRUB_TOP_LEVEL_OS_PROBER" ${OSPROBED})
+fi
+
 for OS in ${OSPROBED} ; do
   DEVICE="`echo ${OS} | cut -d ':' -f 1`"
   LONGNAME="`echo ${OS} | cut -d ':' -f 2 | tr '^' ' '`"
-- 
2.37.3



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH v3] templates: introduce GRUB_TOP_LEVEL_* vars
  2022-10-05  9:22   ` [PATCH v3] " Denton Liu
@ 2022-10-07  5:08     ` Oskari Pirhonen
  2022-10-14 10:11     ` Daniel Kiper
  1 sibling, 0 replies; 13+ messages in thread
From: Oskari Pirhonen @ 2022-10-07  5:08 UTC (permalink / raw)
  To: grub-devel; +Cc: Daniel Kiper, Denton Liu

[-- Attachment #1: Type: text/plain, Size: 1225 bytes --]

On Wed, Oct 05, 2022 at 02:22:38 -0700, Denton Liu wrote:
> 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, GRUB_TOP_LEVEL_XEN and
> GRUB_TOP_LEVEL_OS_PROBER variables to allow users to specify the
> top-level entry.
> 
> Create grub_move_to_front() as a helper function which moves entries to
> the front of a list. This function does the heavy lifting of moving
> the menu entry to the front in each script.
> 
> In 10_netbsd, since there isn't an explicit list variable, extract the
> items that are being iterated through into a list so that we can
> optionally apply grub_move_to_front() to the list before the loop.
> 
> Signed-off-by: Denton Liu <liu.denton@gmail.com>

Reviewed-by: Oskari Pirhonen <xxc3ncoredxx@gmail.com>

I've tested it on Linux, but the other platforms and os-prober are still
untested.

- Oskari

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v3] templates: introduce GRUB_TOP_LEVEL_* vars
  2022-10-05  9:22   ` [PATCH v3] " Denton Liu
  2022-10-07  5:08     ` Oskari Pirhonen
@ 2022-10-14 10:11     ` Daniel Kiper
  1 sibling, 0 replies; 13+ messages in thread
From: Daniel Kiper @ 2022-10-14 10:11 UTC (permalink / raw)
  To: Denton Liu; +Cc: grub-devel, Daniel Kiper, Oskari Pirhonen

On Wed, Oct 05, 2022 at 02:22:38AM -0700, Denton Liu wrote:
> 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, GRUB_TOP_LEVEL_XEN and
> GRUB_TOP_LEVEL_OS_PROBER variables to allow users to specify the
> top-level entry.
>
> Create grub_move_to_front() as a helper function which moves entries to
> the front of a list. This function does the heavy lifting of moving
> the menu entry to the front in each script.
>
> In 10_netbsd, since there isn't an explicit list variable, extract the
> items that are being iterated through into a list so that we can
> optionally apply grub_move_to_front() to the list before the loop.
>
> Signed-off-by: Denton Liu <liu.denton@gmail.com>

I skimmed through the patch and it looks more or less good to me. Just
one nit below...

Please repost the patch by starting new thread instead of replying to
old one and add to CC following addresses: mathieu.desnoyers@efficios.com,
rharwood@redhat.com, samuel.thibault@ens-lyon.org, debian-bsd@lists.debian.org,
xen-devel@lists.xenproject.org.

[...]

> diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in
> index 634bc8a50..f4ae41f86 100644
> --- a/util/grub-mkconfig_lib.in
> +++ b/util/grub-mkconfig_lib.in
> @@ -218,6 +218,30 @@ version_sort ()
>     esac
>  }
>
> +# Given an item as the first argument and a list as the subsequent arguments,
> +# returns the list with the first argument moved to the front if it exists in
> +# the list.
> +grub_move_to_front ()
> +{
> +  item="$1"
> +  shift
> +
> +  item_found=false
> +  for i in "$@"; do
> +    if [ "x$i" = "x$item" ]; then
> +      item_found=true
> +    fi
> +  done
> +
> +  if [ "x$item_found" = xtrue ]; then
> +    echo "$item"
> +  fi
> +  for i in "$@"; do
> +    if [ "x$i" = "x$item" ]; then continue; fi

I prefer

if [ "x$i" = "x$item" ]; then
  continue;
fi

Daniel


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2022-10-14 10:11 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-21 10:24 [PATCH] templates: introduce GRUB_TOP_LEVEL_* vars Denton Liu
2022-08-29  6:11 ` [RESEND PATCH] " Denton Liu
2022-09-21 11:22   ` [RESEND RESEND " Denton Liu
2022-09-27 12:30     ` [RESEND RESEND " Denton Liu
2022-09-29  6:08       ` Oskari Pirhonen
2022-09-29 10:23         ` Denton Liu
2022-09-30  6:53           ` Oskari Pirhonen
2022-09-30 11:06             ` Denton Liu
2022-09-30 11:11 ` [PATCH v2] " Denton Liu
2022-10-02  3:50   ` Oskari Pirhonen
2022-10-05  9:22   ` [PATCH v3] " Denton Liu
2022-10-07  5:08     ` Oskari Pirhonen
2022-10-14 10:11     ` Daniel Kiper

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.