Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1oPi8C-0002VD-PV for mharc-grub-devel@gnu.org; Sun, 21 Aug 2022 06:24:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55942) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oPi8C-0002V5-0l for grub-devel@gnu.org; Sun, 21 Aug 2022 06:24:36 -0400 Received: from mail-qt1-x82d.google.com ([2607:f8b0:4864:20::82d]:45602) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oPi8A-0003Ww-CM for grub-devel@gnu.org; Sun, 21 Aug 2022 06:24:35 -0400 Received: by mail-qt1-x82d.google.com with SMTP id j17so6094859qtp.12 for ; Sun, 21 Aug 2022 03:24:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc; bh=Gm3s3sFvOFgBn733h6tzqAKyoORE0QbGkk/oz1JCo1I=; b=h1Zop8HNyodEv0spI2uAdio7FO8K0PIONDlp7coXQQEMVy++4/jPQ8POj3wnRrCfAI 0dQOxcp5TxNaH4UthYs+zDCfhz/CuMEizjO62na90lcWnhFijY1rSZdDDrwYtIfoZcbO DkBKfp3EyhJ4oCdA1rdrkIf29J0FRjY1jMMokM4TUbxg5b0i30U7pGQYvcv0vQFJuAC8 O6/sp+xEzokaqcNRA0V4FghufgDjNPQCS8jwVo9DviRcOv1aVXZkNrcbCY/MXw6JVNeA 4Gdrfh12W9D1wtSM7CNp4Y2rmxwgm+/rMhvKOWkrAjv+YO4kaSPZTjXwgX2oOH1RltVM 08Ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc; bh=Gm3s3sFvOFgBn733h6tzqAKyoORE0QbGkk/oz1JCo1I=; b=jmm554T49kJpW/kllX82krjBPNO2XWn9BVGCUOOGwBMhbYlqTlIrpojsC0FpwFuHIp CuPBgNBQGB9Zak2wbmXC5XYSIqWK1yr3yfFsH2brHQWgFWRP/Kd7YPdcCpQBjJ5j2bw/ 9jHIC6//CEnCLUCqBtsk5b6sjWQMnW/5BhNrRqI9QOfvwdlIJAuKhwp21CL+z7BWKusI WFwVrA4OedyIZmRl426RZngpFWAIJxIMz16Go3N1usV3At4TjZFhu/SLq3qOmlE905c1 8vg+7yaE09DiSWLTjcvZWTHSh78uJ7JjGSJ7gHPMQ81tfRNEbNo8UZg9Sx2OAXxJvvPJ 8xiw== X-Gm-Message-State: ACgBeo2WHoIx44h/FhubytEmKraT7XVVSCVpuRxE1Y4nU4c3uoTu9O12 Lvk+X/hjhkHM2rdQmQtBJE5pnT/QPNU= X-Google-Smtp-Source: AA6agR6O9sDvefheOAlxtQA68KrdFvWRLqqjq/9xdLKeWO0tzVNS78muJMCU4LtKMZF4hQ7yEcTC+A== X-Received: by 2002:a05:622a:143:b0:344:95bf:8f02 with SMTP id v3-20020a05622a014300b0034495bf8f02mr10013822qtw.202.1661077472797; Sun, 21 Aug 2022 03:24:32 -0700 (PDT) Received: from archbookpro.ht.home (cpe688f2ec66813-cm688f2ec66810.cpe.net.fido.ca. [72.137.15.250]) by smtp.gmail.com with ESMTPSA id s13-20020a05620a254d00b006b633dc839esm8500177qko.66.2022.08.21.03.24.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Aug 2022 03:24:32 -0700 (PDT) From: Denton Liu To: grub-devel@gnu.org Subject: [PATCH] templates: introduce GRUB_TOP_LEVEL_* vars Date: Sun, 21 Aug 2022 06:24:21 -0400 Message-Id: <20220821102421.169229-1-liu.denton@gmail.com> X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::82d; envelope-from=liu.denton@gmail.com; helo=mail-qt1-x82d.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: Sun, 21 Aug 2022 10:24:36 -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