Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1oSXzt-00035G-SC for mharc-grub-devel@gnu.org; Mon, 29 Aug 2022 02:11:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57766) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oSXzr-00034U-Pn for grub-devel@gnu.org; Mon, 29 Aug 2022 02:11:43 -0400 Received: from mail-qk1-x735.google.com ([2607:f8b0:4864:20::735]:42930) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oSXzp-0002Cd-Td for grub-devel@gnu.org; Mon, 29 Aug 2022 02:11:43 -0400 Received: by mail-qk1-x735.google.com with SMTP id h27so5354621qkk.9 for ; Sun, 28 Aug 2022 23:11:41 -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; bh=Gm3s3sFvOFgBn733h6tzqAKyoORE0QbGkk/oz1JCo1I=; b=i80VE72ZURSOq9zBqBHxs92X3cFokQgO+yBYeZZ1DvQzp5kYRMmMHZDIR4m7yVvaFD G5TobeYCZXE2FiRb8Llk5llYfX33iZLFFwHFOljpWk9ppBL5zDzy1RpEp6/95ZPqUUOx e173BV67tonvc1shAjinjvvBPwXG1TbQCouKYdKy/VMMWbZYpCQtxWCJ+TiVd+NUnjQt geig6qhOnXYOvJNa+ynQzm/R5eXrzEdoWUNBMbMeMccXOj9jR40yailfj1q0NP5DPDRg ZEs6bMkZxmIEOWWYBgJOip2iTa0ZBOEBVOpXorTBWhCe1XErR01zys7lgW68UxP47Ae3 76Lg== 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; bh=Gm3s3sFvOFgBn733h6tzqAKyoORE0QbGkk/oz1JCo1I=; b=0vURGTVb2bO5S9H782R6T8VtStgC6bzmzKJcY5CjtTp4g+rBmgfY1BeX5eaztU/gBA Xm2qNLSFLdd4mapUGoRNY/hUClLXK6Y/fHIa2dtEI0IVGFWpsnXEF/NjgJ73HRhD4AAJ uoLDJmhjNAnh20ydIqZLRbzT7VbX2DI6x1G7XWq29UCMbfkrTIr/hC17Yivd0EOSYf80 xa5sAnut17nEOyD/4QN9P5O0mS9C3JGBfLQWRn3pztSArs/ZT2tbp34ya5xdjH0piF+f 0TgQvivaix/B1Fy6h1dPbVK4Ppby4vzCVNoKw/chj1pIRxMqwdaKIoFaX0Vl8JGV2GN7 dXIA== X-Gm-Message-State: ACgBeo0YPe+8tY6f3LKtFi3vGJiuenXXyANEwOb8o5pjBAOhBJARrSmn 3zKJ7rOr10DRCxmuoJI5ih1u9b3Tzpc= X-Google-Smtp-Source: AA6agR5qx8BQvClpEpggOX73VZZqzsGI7ovzNSPO5f8eLku0QflAjQ/l/t/dKI1c2pUM6ZUMCKiUDA== X-Received: by 2002:a05:620a:2618:b0:6bb:515e:c73f with SMTP id z24-20020a05620a261800b006bb515ec73fmr7439171qko.412.1661753500309; Sun, 28 Aug 2022 23:11:40 -0700 (PDT) Received: from archbookpro.ht.home (cpe688f2ec66813-cm688f2ec66810.cpe.net.fido.ca. [72.137.15.250]) by smtp.gmail.com with ESMTPSA id dt47-20020a05620a47af00b006b61b2cb1d2sm5265357qkb.46.2022.08.28.23.11.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Aug 2022 23:11:39 -0700 (PDT) From: Denton Liu To: grub-devel@gnu.org Subject: [RESEND PATCH] templates: introduce GRUB_TOP_LEVEL_* vars Date: Mon, 29 Aug 2022 02:11:33 -0400 Message-Id: <20220829061133.4085-1-liu.denton@gmail.com> X-Mailer: git-send-email 2.37.2 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::735; envelope-from=liu.denton@gmail.com; helo=mail-qk1-x735.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, T_SCC_BODY_TEXT_LINE=-0.01 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: Mon, 29 Aug 2022 06:11: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.2