Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1oaxoT-0005jT-EJ for mharc-grub-devel@gnu.org; Wed, 21 Sep 2022 07:22:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47102) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oaxoQ-0005i4-H1 for grub-devel@gnu.org; Wed, 21 Sep 2022 07:22:43 -0400 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]:38910) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oaxoK-0004fb-Py for grub-devel@gnu.org; Wed, 21 Sep 2022 07:22:39 -0400 Received: by mail-pl1-x62e.google.com with SMTP id x1so5318187plv.5 for ; Wed, 21 Sep 2022 04:22:35 -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:to:from:from:to:cc:subject:date; bh=d3iyROCWG11XCASoBUgV4aDYF1gVrCcsM8b4GE9/Ybw=; b=OGr9Fy849QyNySNzmn0eRhCGpfQ9iVWkg8XLY5CqUhDP6qEOLXTacmZPgfzhbQCDeF UO1glla23OFsI0uXKhxO3S8rz13T/sMY9hvpzuzqqRxDGIfvuyAg43BfE1Tc86IcLPOf HKeKC8rRpSSdvP48yy40LVDOPOW8YkJuGELLxj+nk3nVCsu2r9KfzbJOxgTxRR5mcEgt xL+gw/m+cpCS4Dk/A/7tkkPCfogwCRLe86BRp53un3Gnl+nBuivVlhZWiGfvaTFCcCPA yP+22Cg3eCyYV6vInuxVC7+Ec90JokcvSmoGPGrw3RCkMMpP2kLNSgrU/fDSAhLAXYPI Qh1w== 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:to:from:x-gm-message-state:from:to:cc :subject:date; bh=d3iyROCWG11XCASoBUgV4aDYF1gVrCcsM8b4GE9/Ybw=; b=p99lSjGe2Z+6UnRMeLC73MUoxhkm9fqeJYQj5aXyiPWM+jl1n/nOJ+Unpia850f03h rqtWfnaD/vWFHQXMcQx2sDyKOqepAMm27PLFAsWA1cFGvq0t4IDOQsADOK2AtqUh4q4J UGNBVo18T1/Mhc1bcF0cu2qqyN49WE/16VPtuD83N2GdZFh1rjO32F8LWF6jLy2Uvktc nV5Bkl7J04MgQ4Y/G6eMHN0MnsdJ9+KHm7HBw5/wJ7biGIqegDh74D53EQWX7uhjzGg3 iyK6Zv+LN+6fcar/vXVk52A2N0Y872QQ4Xc9tTW8rISIpwb40lWRhZzAfM98TkGlGk3p CxxA== X-Gm-Message-State: ACrzQf0lkOGhA/ocK8XjREjJz8qDJPpX2dXa1GWDU1vNN5ZzwxypNZ65 Rq10tl55GGuv/2/x8YSr2QQZ1VW1GLQ= X-Google-Smtp-Source: AMsMyM62xKZeL0NXcrj7iz2AmKVhvJltO++NaiUHAyAWxB1v1fq3mCUh6Ql2KrPYiHw5DDxbO2EDsA== X-Received: by 2002:a17:902:d50f:b0:178:6505:fae3 with SMTP id b15-20020a170902d50f00b001786505fae3mr4337647plg.54.1663759354290; Wed, 21 Sep 2022 04:22:34 -0700 (PDT) Received: from archbookpro.localdomain (136-25-1-99.cab.webpass.net. [136.25.1.99]) by smtp.gmail.com with ESMTPSA id i1-20020a626d01000000b005363bc65bafsm1855330pfc.57.2022.09.21.04.22.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Sep 2022 04:22:33 -0700 (PDT) From: Denton Liu To: grub-devel@gnu.org Subject: [RESEND RESEND PATCH] templates: introduce GRUB_TOP_LEVEL_* vars Date: Wed, 21 Sep 2022 04:22:25 -0700 Message-Id: <20220921112225.145616-1-liu.denton@gmail.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220829061133.4085-1-liu.denton@gmail.com> References: <20220829061133.4085-1-liu.denton@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::62e; envelope-from=liu.denton@gmail.com; helo=mail-pl1-x62e.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: Wed, 21 Sep 2022 11:22:44 -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