From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1ga8eg-0003Ab-EK for mharc-grub-devel@gnu.org; Thu, 20 Dec 2018 19:27:06 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57635) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ga8ee-0003AP-O0 for grub-devel@gnu.org; Thu, 20 Dec 2018 19:27:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ga8eZ-0000v2-I9 for grub-devel@gnu.org; Thu, 20 Dec 2018 19:27:04 -0500 Received: from mta.tntech.edu ([149.149.2.87]:28970) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ga8eZ-0000Af-6H for grub-devel@gnu.org; Thu, 20 Dec 2018 19:26:59 -0500 Received: from norden.math.tntech.edu (unknown [149.149.136.15]) by mta.tntech.edu (Postfix) with ESMTP id EB19D3000064; Thu, 20 Dec 2018 18:26:20 -0600 (CST) Received: by norden.math.tntech.edu (Postfix, from userid 742) id D4D9A2572B73; Thu, 20 Dec 2018 18:26:20 -0600 (CST) From: Jeff Norden To: grub-devel@gnu.org Subject: Re: Proposed PATCH to allow control of the kernel ordering in grub.cfg In-Reply-To: (message from Jeff Norden on Wed, 19 Dec 2018 00:50:21 -0600) Date: Thu, 20 Dec 2018 18:26:20 -0600 Message-ID: MIME-Version: 1.0 Content-Type: text/plain X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 149.149.2.87 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 21 Dec 2018 00:27:05 -0000 Hi Daniel, Thanks for the quick reply! I've made the suggested changes and attached a "git format-patch" patch below. Hopefully this is what you need. I'm not much of a git-expert. Thanks again. Have a great Holiday Season! -Jeff On Thu, 20 Dec 2018, Daniel Kiper wrote: > This looks like nice commit message. So, please rebase your patch on > latest GRUB2 master branch and repost it using "git format-patch" and > "git send-email". And please do not forget to add your Signed-off-by. > > And some minor comments below... Signed-off-by: Jeffrey Norden --- docs/grub.texi | 18 ++++++++++++++++++ util/grub-mkconfig.in | 3 ++- util/grub.d/10_linux.in | 9 ++++++++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/docs/grub.texi b/docs/grub.texi index ecaba9d5c..4aaa151f8 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -1502,6 +1502,24 @@ and @samp{default} (@pxref{default}) environment variables as well as saved default entry using @command{grub-set-default} and value used with @command{grub-reboot}. +@item GRUB_PREFERRED_KERNEL +If this option is set, @command{grub-mkconfig} will list kernels that +match its value before others. In particular, the ``top-level'' menu +entry (assuming submenus are enabled) will be the one with the highest +version number that matches @samp{GRUB_PREFERRED_KERNEL}. For +example, @verb{|GRUB_PREFERRED_KERNEL="4.14"|} will put the 4.14 kernel +first in @file{grub.cfg}, even if newer kernel(s) are found. + +Matching is done via @command{egrep} against the file name of the +kernel, so regular expressions can be used. For example: +@verb{|GRUB_PREFERRED_KERNEL='4\.1[0-6]'|} will put any kernels matching +4.10 thru 4.16 first, starting with the highest version number. Or, +@verb{|GRUB_PREFERRED_KERNEL='vmlinuz-3\.16-x86_64'|} would match a +specific kernel file. Note that the simple example in the previous +paragraph can be written more carefully as +@verb{|GRUB_PREFERRED_KERNEL='4\.14'|} to force the @samp{.} to match +a period instead of an arbitrary character. + @item GRUB_ENABLE_CRYPTODISK If set to @samp{y}, @command{grub-mkconfig} and @command{grub-install} will check for encrypted disks and generate additional commands needed to access diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in index 33332360e..8d6aecf22 100644 --- a/util/grub-mkconfig.in +++ b/util/grub-mkconfig.in @@ -238,7 +238,8 @@ export GRUB_DEFAULT \ GRUB_ENABLE_CRYPTODISK \ GRUB_BADRAM \ GRUB_OS_PROBER_SKIP_LIST \ - GRUB_DISABLE_SUBMENU + GRUB_DISABLE_SUBMENU \ + GRUB_PREFERRED_KERNEL if test "x${grub_cfg}" != "x"; then rm -f "${grub_cfg}.new" diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in index 4532266be..32affd9d6 100644 --- a/util/grub.d/10_linux.in +++ b/util/grub.d/10_linux.in @@ -193,7 +193,14 @@ submenu_indentation="" is_top_level=true while [ "x$list" != "x" ] ; do - linux=`version_find_latest $list` + linux="" + if [ "x${GRUB_PREFERRED_KERNEL}" != "x" ]; then + linux=`echo $list | tr ' ' '\n' | egrep "${GRUB_PREFERRED_KERNEL}"` + fi + if [ "x$linux" = "x" ]; then + linux=$list + fi + linux=`version_find_latest $linux` gettext_printf "Found linux image: %s\n" "$linux" >&2 basename=`basename $linux` dirname=`dirname $linux` -- 2.19.2