All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Add config option to prefer Linux kernel versions by substring match
@ 2014-09-07 19:37 Doug Brunner
  2014-09-11 17:52 ` Jordan Uggla
  2014-09-13 16:01 ` Andrei Borzenkov
  0 siblings, 2 replies; 4+ messages in thread
From: Doug Brunner @ 2014-09-07 19:37 UTC (permalink / raw)
  To: grub-devel

Hi all,

First time submitting - please let me know if I'm doing anything wrong.

This patch adds an option, GRUB_LINUX_PREF_VERSION_SUBSTR, that can be set to prioritize Linux kernels containing a
given substring. This takes precedence over version ordering, so if you have 3.14.1-generic, 3.14.2-generic,
3.8.13-fnord1, and 3.8.13-fnord2 and the substring is 'fnord', the order is:
3.8.13-fnord2
3.8.13-fnord1
3.14.2-generic
3.14.1-generic

Rationale: I and others, (see e.g. http://askubuntu.com/questions/216398/set-older-kernel-as-default-grub-entry) needed
to change the Linux kernel version GRUB sets as default. The process is error-prone: you have to figure out where in the
GRUB menu it will appear, then enter that in /etc/default/grub, and if the menu position changes due to new kernels
added to the system you have to do it all over again. I had older kernels with a distinctive local version naming scheme
that I wanted preferred over the stock kernels, but it could also be used to specify a particular kernel version.

* util/grub-mkconfig.in: Add export of GRUB_LINUX_PREF_VERSION_SUBSTR
* util/grub.d/10_linux.in: Handle GRUB_LINUX_PREF_VERSION_SUBSTR when adding kernels

Signed-off-by: Doug Brunner <doug@doug-brunner.com>
---
 util/grub-mkconfig.in   |  3 ++-
 util/grub.d/10_linux.in | 22 ++++++++++++++++++----
 2 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in
index d1fae49..9a3a3e9 100644
--- a/util/grub-mkconfig.in
+++ b/util/grub-mkconfig.in
@@ -224,7 +224,8 @@ export GRUB_DEFAULT \
   GRUB_ENABLE_CRYPTODISK \
   GRUB_BADRAM \
   GRUB_OS_PROBER_SKIP_LIST \
-  GRUB_DISABLE_SUBMENU
+  GRUB_DISABLE_SUBMENU \
+  GRUB_LINUX_PREF_VERSION_SUBSTR
 
 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 d2e2a8f..0c447f6 100644
--- a/util/grub.d/10_linux.in
+++ b/util/grub.d/10_linux.in
@@ -173,9 +173,25 @@ title_correction_code=
 # yet, so it's empty. In a submenu it will be equal to '\t' (one tab).
 submenu_indentation=""
 
+pref_list=""
+non_pref_list=""
+for entry in $list; do
+  if [[ "$entry" == *$GRUB_LINUX_PREF_VERSION_SUBSTR* ]]; then
+    pref_list="$pref_list $entry"
+  else
+    non_pref_list="$non_pref_list $entry"
+  fi
+done
+
 is_top_level=true
-while [ "x$list" != "x" ] ; do
-  linux=`version_find_latest $list`
+while [ "x$pref_list$non_pref_list" != "x" ] ; do
+  if [ "x$pref_list" != "x" ]; then
+    linux=`version_find_latest $pref_list`
+    pref_list=`echo $pref_list | tr ' ' '\n' | fgrep -vx "$linux" | tr '\n' ' '`
+  else
+    linux=`version_find_latest $non_pref_list`
+    non_pref_list=`echo $non_pref_list | tr ' ' '\n' | fgrep -vx "$linux" | tr '\n' ' '`
+  fi
   gettext_printf "Found linux image: %s\n" "$linux" >&2
   basename=`basename $linux`
   dirname=`dirname $linux`
@@ -240,8 +256,6 @@ while [ "x$list" != "x" ] ; do
     linux_entry "${OS}" "${version}" recovery \
                 "single ${GRUB_CMDLINE_LINUX}"
   fi
-
-  list=`echo $list | tr ' ' '\n' | fgrep -vx "$linux" | tr '\n' ' '`
 done
 
 # If at least one kernel was found, then we need to



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] Add config option to prefer Linux kernel versions by substring match
  2014-09-07 19:37 [PATCH] Add config option to prefer Linux kernel versions by substring match Doug Brunner
@ 2014-09-11 17:52 ` Jordan Uggla
  2014-09-13 16:01 ` Andrei Borzenkov
  1 sibling, 0 replies; 4+ messages in thread
From: Jordan Uggla @ 2014-09-11 17:52 UTC (permalink / raw)
  To: The development of GNU GRUB

On Sun, Sep 7, 2014 at 12:37 PM, Doug Brunner <doug@doug-brunner.com> wrote:
> Hi all,
>
> First time submitting - please let me know if I'm doing anything wrong.
>
> This patch adds an option, GRUB_LINUX_PREF_VERSION_SUBSTR, that can be set to prioritize Linux kernels containing a
> given substring. This takes precedence over version ordering, so if you have 3.14.1-generic, 3.14.2-generic,
> 3.8.13-fnord1, and 3.8.13-fnord2 and the substring is 'fnord', the order is:
> 3.8.13-fnord2
> 3.8.13-fnord1
> 3.14.2-generic
> 3.14.1-generic
>
> Rationale: I and others, (see e.g. http://askubuntu.com/questions/216398/set-older-kernel-as-default-grub-entry) needed
> to change the Linux kernel version GRUB sets as default. The process is error-prone: you have to figure out where in the
> GRUB menu it will appear, then enter that in /etc/default/grub, and if the menu position changes due to new kernels
> added to the system you have to do it all over again. I had older kernels with a distinctive local version naming scheme
> that I wanted preferred over the stock kernels, but it could also be used to specify a particular kernel version.

Your rationale, as stated, is completely solved by using the menuentry
ID, as documented in "info -f grub -n 'Simple configuration' ", rather
than using a menuentry number. The answer given to that askubuntu.com
question is a poor one, as noted by one of the commentors (though that
commenter recommends menuentry titles, which have their own issues,
again as documented in the texinfo manual).

-- 
Jordan Uggla (Jordan_U on irc.freenode.net)


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Add config option to prefer Linux kernel versions by substring match
  2014-09-07 19:37 [PATCH] Add config option to prefer Linux kernel versions by substring match Doug Brunner
  2014-09-11 17:52 ` Jordan Uggla
@ 2014-09-13 16:01 ` Andrei Borzenkov
  1 sibling, 0 replies; 4+ messages in thread
From: Andrei Borzenkov @ 2014-09-13 16:01 UTC (permalink / raw)
  To: The development of GNU GRUB; +Cc: doug

В Sun, 07 Sep 2014 12:37:36 -0700
Doug Brunner <doug@doug-brunner.com> пишет:

> Hi all,
> 
> First time submitting - please let me know if I'm doing anything wrong.
> 
> This patch adds an option, GRUB_LINUX_PREF_VERSION_SUBSTR, that can be set to prioritize Linux kernels containing a
> given substring. This takes precedence over version ordering, so if you have 3.14.1-generic, 3.14.2-generic,
> 3.8.13-fnord1, and 3.8.13-fnord2 and the substring is 'fnord', the order is:
> 3.8.13-fnord2
> 3.8.13-fnord1
> 3.14.2-generic
> 3.14.1-generic
> 

You can simply disable default 10_linux script and use your own that
does whatever ordering you prefer. This is too specific for upstream
distribution. But it really seems like we need some additional layer on
top of raw grub script that allows manual reordering of entries among
others.

> +  if [[ "$entry" == *$GRUB_LINUX_PREF_VERSION_SUBSTR* ]]; then

No, grub scripts do not require bash, so this is not going to work.



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Add config option to prefer Linux kernel versions by substring match
       [not found] <mailman.69.1410537627.19647.grub-devel@gnu.org>
@ 2014-09-12 21:26 ` Doug Brunner
  0 siblings, 0 replies; 4+ messages in thread
From: Doug Brunner @ 2014-09-12 21:26 UTC (permalink / raw)
  To: grub-devel

> On Sun, Sep 7, 2014 at 12:37 PM, Doug Brunner <doug@doug-brunner.com> wrote:
>> Hi all,
>>
>> First time submitting - please let me know if I'm doing anything wrong.
>>
>> This patch adds an option, GRUB_LINUX_PREF_VERSION_SUBSTR, that can be set to prioritize Linux kernels containing a
>> given substring. This takes precedence over version ordering, so if you have 3.14.1-generic, 3.14.2-generic,
>> 3.8.13-fnord1, and 3.8.13-fnord2 and the substring is 'fnord', the order is:
>> 3.8.13-fnord2
>> 3.8.13-fnord1
>> 3.14.2-generic
>> 3.14.1-generic
>>
>> Rationale: I and others, (see e.g. http://askubuntu.com/questions/216398/set-older-kernel-as-default-grub-entry) needed
>> to change the Linux kernel version GRUB sets as default. The process is error-prone: you have to figure out where in the
>> GRUB menu it will appear, then enter that in /etc/default/grub, and if the menu position changes due to new kernels
>> added to the system you have to do it all over again. I had older kernels with a distinctive local version naming scheme
>> that I wanted preferred over the stock kernels, but it could also be used to specify a particular kernel version.
> 
> Your rationale, as stated, is completely solved by using the menuentry
> ID, as documented in "info -f grub -n 'Simple configuration' ", rather
> than using a menuentry number. The answer given to that askubuntu.com
> question is a poor one, as noted by one of the commentors (though that
> commenter recommends menuentry titles, which have their own issues,
> again as documented in the texinfo manual).
> 
I think there would still be some usability gains; if I understand it correctly, to use menuentry IDs, I would have to
enter e.g. 'gnulinux-advanced-UUID>gnulinux-3.8.13-fnord1-advanced-UUID', where UUID is for my root partition. This is
still somewhat laborious to compose; for my use case, it also requires redoing the entry every time I build a new -fnord
kernel.

If I can come up with a way of making GRUB_DEFAULT use a substring match rather than exact match (in the case of
multiple matches, perhaps choosing the latest kernel version that matches) would that be acceptable?

Doug Brunner


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-09-13 16:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-07 19:37 [PATCH] Add config option to prefer Linux kernel versions by substring match Doug Brunner
2014-09-11 17:52 ` Jordan Uggla
2014-09-13 16:01 ` Andrei Borzenkov
     [not found] <mailman.69.1410537627.19647.grub-devel@gnu.org>
2014-09-12 21:26 ` Doug Brunner

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.