Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1oeDvZ-0003CZ-6M for mharc-grub-devel@gnu.org; Fri, 30 Sep 2022 07:11:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49088) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oeDvX-0003C5-C8 for grub-devel@gnu.org; Fri, 30 Sep 2022 07:11:31 -0400 Received: from mail-pg1-x535.google.com ([2607:f8b0:4864:20::535]:42691) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oeDvV-0006uO-DH for grub-devel@gnu.org; Fri, 30 Sep 2022 07:11:31 -0400 Received: by mail-pg1-x535.google.com with SMTP id e129so3876820pgc.9 for ; Fri, 30 Sep 2022 04:11:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=1PaUX5DUqmFsb+7YjThK5T6u0m7JDA9vpOZIWeAOCfw=; b=TT2aq954Q3N5AefDvFzwNbBDmtmCA8sg/E658Qnv7SBZ5+IKG9LuwVVMbA2jV3WDEa SucJJsJJV3fatQVi1v7Rp0MO1eEMUPHnjlkV0Rtcj7u1eCNP0lofaaSZPUTpohhanXjs 83afb7z6EqEzbuXPBTIEuDdZgeqQsYHx0mWVFWXxw3GR/Rbpk9s5LzNgjoua16gPUQ0Y gVgmvMlYSca6aINk1sCqMEjhYG6u0w1hrlyIItJ2VqSBJzY0597zyy2uQysWc3bki0/6 7GzkEFC8MHEZW0/MMKU3F/Afcco2fcu3EhQR12AsN5tEee1StPF2FzVhjvVIL4bXySZX QoKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=1PaUX5DUqmFsb+7YjThK5T6u0m7JDA9vpOZIWeAOCfw=; b=DwJ6H5y0gnKCX1eb/MCtbnmsE6PyAYZk/MlLkO1K3SPxRwVTBcNGLMscgNnWWsjLLO lN88Hh0cZpC/D1do1cCe9YYnVOuQd/f9+EqoMgL8nm4XxX08Mx84uEchxYhAZKA6j7j6 q1Jzloy1JNDEHCbtANOnVpPsG1HSP7NNYlp2PNnGkUsYJTVtQaDiv0K6uMjU2Rf+VovK 0U30kieW+bdjMcxCqJNw3yXegSpxiNNll/JVWVBjaHfuwepl1UsI3QXWmSvCrGhZVwK1 rHULhII4iuu+mCC+NFW06V7pt4eLGmAZt+5snZUxK3vVD0bsbiJCdtKuiGfEqkDGBOuy YCTA== X-Gm-Message-State: ACrzQf3zR1fY97KG2V3fj/1gGYbZ1eUS9SGaC8dtyc2aoN6jaH+YI0UX Si4pou5KeabrDOIv+9JZIOWcV/BGYCw= X-Google-Smtp-Source: AMsMyM5FWyRyv4N8QTjCqbMoWYbgEBJY+x6vGCDRocXS1iXfToc9JJhLmjHr5C/0vuhLQ11+LzJbiQ== X-Received: by 2002:a05:6a00:14d5:b0:542:9c32:ab27 with SMTP id w21-20020a056a0014d500b005429c32ab27mr8597587pfu.64.1664536287475; Fri, 30 Sep 2022 04:11:27 -0700 (PDT) Received: from archbookpro.localdomain (136-25-1-99.cab.webpass.net. [136.25.1.99]) by smtp.gmail.com with ESMTPSA id k5-20020a170902694500b00172e19c5f8bsm1615301plt.168.2022.09.30.04.11.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Sep 2022 04:11:27 -0700 (PDT) From: Denton Liu To: grub-devel@gnu.org Cc: Daniel Kiper , Oskari Pirhonen Subject: [PATCH v2] templates: introduce GRUB_TOP_LEVEL_* vars Date: Fri, 30 Sep 2022 04:11:11 -0700 Message-Id: <20220930111111.67328-1-liu.denton@gmail.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220821102421.169229-1-liu.denton@gmail.com> References: <20220821102421.169229-1-liu.denton@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::535; envelope-from=liu.denton@gmail.com; helo=mail-pg1-x535.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 30 Sep 2022 11:11:31 -0000 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 --- 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