Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1od9jx-0005Si-CU for mharc-grub-devel@gnu.org; Tue, 27 Sep 2022 08:31:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60278) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1od9jp-0005Mk-AN for grub-devel@gnu.org; Tue, 27 Sep 2022 08:31:01 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]:33309) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1od9jl-0004jL-Dd for grub-devel@gnu.org; Tue, 27 Sep 2022 08:31:00 -0400 Received: by mail-pf1-x42d.google.com with SMTP id w2so9590422pfb.0 for ; Tue, 27 Sep 2022 05:30:56 -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=d3iyROCWG11XCASoBUgV4aDYF1gVrCcsM8b4GE9/Ybw=; b=itRmpeg5oXVFqMJZ9D/NmFeuK4VXLXPcwJ4Hp7/g9hiVbPyas2NH/copbpukF850zt kEqkphIloNb7j1NPYtxZ0YMcXXcCKD1W5H/IR8aVelE3644eIDX6R67Gr9adA6Rkeaej HBxK477yc1oB6Ir2UmXjcgnXOA8pN3xPt0yZT1eBSXn8IUknOVh7kBMTr3jlJwKgM3d1 t9AsCAlbWTI/PC19/xty29v9RIc7chCM37kVtxJOM/LodApdEFK8fz/Cw4C4JTXfhg2U TmKyKayNVAJJum4ACRT8mildgWLsoJI9bnx7lw77G5pd5Yhhdc7jGsxPR8U8cz+PP28d c/qQ== 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=d3iyROCWG11XCASoBUgV4aDYF1gVrCcsM8b4GE9/Ybw=; b=i+N1aWKdU3KknSKuT4AcWbAoMIUk3ywrug5XGxJKGsi5MZ4V9yB5xpQnYODwUTv8N0 JvwGWkf1XdD9aYiuMHOSHrPXEtkVTxRfX6iANeqp4NF8DGe5FEiUrHLIVL3jMe2mS1ZH l5ZAhfmWk00BaE6W99RWYXKPXzqgqNUuPLyk+LibmdQFqAW41n6iRLOQrGvewT4AjN2q DzeEMPM1zV24yf5M9bur1J3XKvYAq2Ns7TVm5lOqCLx25cPdr880Q+d/XPmM4FbWlH+J cxSzSVLOJJ0GclO20xmS458rwFGZCcRj9NaCaokZvYlhc3O8XtELvBc06O/IKgtSLHce s0fA== X-Gm-Message-State: ACrzQf16itjwjKPkVEi9yeXvALuVsSL85B4wYOpJoXbY/U2x/pDnIqM/ YcYHEo54QI3gQeLsMlM9AyXCBWgGSww= X-Google-Smtp-Source: AMsMyM4rYaecHaMDp/mhpfctqHZDn9lK60ajqbgAmeajVnFZkOm0LDjBHKaHoTrp9Lq7jPrXKfRKzA== X-Received: by 2002:a05:6a00:228c:b0:542:e65c:98 with SMTP id f12-20020a056a00228c00b00542e65c0098mr28659073pfe.79.1664281855233; Tue, 27 Sep 2022 05:30:55 -0700 (PDT) Received: from archbookpro.localdomain (136-25-1-99.cab.webpass.net. [136.25.1.99]) by smtp.gmail.com with ESMTPSA id b9-20020aa78ec9000000b00540d75197e5sm1653555pfr.47.2022.09.27.05.30.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Sep 2022 05:30:54 -0700 (PDT) From: Denton Liu To: grub-devel@gnu.org Cc: Daniel Kiper Subject: [RESEND RESEND RESEND PATCH] templates: introduce GRUB_TOP_LEVEL_* vars Date: Tue, 27 Sep 2022 05:30:45 -0700 Message-Id: <20220927123045.100271-1-liu.denton@gmail.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220921112225.145616-1-liu.denton@gmail.com> References: <20220921112225.145616-1-liu.denton@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::42d; envelope-from=liu.denton@gmail.com; helo=mail-pf1-x42d.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: Tue, 27 Sep 2022 12:31:01 -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_LINUX and GRUB_TOP_LEVEL_XEN variables to allow users to specify the top-level entry. Signed-off-by: Denton Liu --- 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