FS#28081 - [grub] Incorrect ordering of kernels in grub.cfg generated by grub-mkconfig

Attached to Project: Arch Linux
Opened by Xavier D. (magicrhesus) - Tuesday, 24 January 2012, 13:05 GMT
Last edited by Buggy McBugFace (bugbot) - Saturday, 25 November 2023, 20:13 GMT
Task Type Bug Report
Category Packages: Core
Status Closed
Assigned To Christian Hesse (eworm)
Architecture All
Severity Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 20
Private No



The detection order is not correct.
If you have linux-lts & linux installed, linux-lts is detected as more recent than linux.

Additional info:
* package version(s)
* config and/or log files etc.

Package version: grub2-common 1:1.99-6

Steps to reproduce:

Install linux & linux-lts package, run grub-mkconfig.

Attached a patch which permits to detect them in the correct order (inspired from one of the Fedora bugtracker)
This task depends upon

Closed by  Buggy McBugFace (bugbot)
Saturday, 25 November 2023, 20:13 GMT
Reason for closing:  Moved
Additional comments about closing:  https://gitlab.archlinux.org/archlinux/p ackaging/packages/grub/issues/1
Comment by Keshav Amburay (the.ridikulus.rat) - Thursday, 02 February 2012, 06:26 GMT
Post this issue in bug-grub ML or #grub irc.
Comment by Keshav Amburay (the.ridikulus.rat) - Monday, 19 March 2012, 11:28 GMT
Someone please change the title to be more descriptive, like "[grub2-common] Incorrect ordering of kernels in grub.cfg generated by grub-mkconfig"
Comment by Keshav Amburay (the.ridikulus.rat) - Tuesday, 03 April 2012, 04:34 GMT
Is the detection order correct in grub2 2.00beta3-1 ?
Comment by Xavier D. (magicrhesus) - Tuesday, 03 April 2012, 13:01 GMT
Comment by Keshav Amburay (the.ridikulus.rat) - Monday, 16 April 2012, 13:35 GMT
@magicrhesus: Did you contact upstream about this?
Comment by Andreas Källberg (Hjulle) - Monday, 06 October 2014, 06:57 GMT
  • Field changed: Percent Complete (100% → 0%)
The proposed patch actually finds the _oldest_ kernel according to sort -V. According to normal version ordering vmlinuz-linux _is_ older than vmlinuz-linux-lts. The arch-linux kernel naming system causes this bug.
Comment by Cherrot Luo (cherrot) - Saturday, 08 October 2016, 15:58 GMT
Seems that this issue still remains on grub-mkconfig (GRUB) 2.02~beta3 ?
Comment by deusstultus (deusstultus) - Tuesday, 07 February 2017, 08:19 GMT
I move to reclassify this and solve as a distribution bug which may eventually be handled through feature request at upstream #42597. (Edit fixed bug number)

1) Kernel naming is a distribution choice, there is no universal right answer here. In fact, archlinux deviates from upstream norm.
2) Given archlinux rolling release philosophy, it stands to reason that if a user has both linux and linux-lts installed, linux should be pushed as the default. Let user configuration drive changes from this norm rather than relying on grub parsing to guess.

Three real options here:
1) Revamp arch implementation to make use of GRUB_DEFAULT, configuring IDs a bit differently
2) Apply patch from upstream #4259 or something akin to reporter here, acknowledging that an alpha sorted listing doesn't serve much more than solving for the current core repository kernels. touch /boot/vmlinuz-zzz and suddenly there's a new priority.
3) Refactor 10_linux so that the distribution preferred kernel is made first if available.

Attached is a hack for route 3 which I have verified.

I'll file up with an upstream tag on this new direction, but hold that this issue is a distribution bug which could be served in time by an upstream feature.
Comment by vlamnire0 (blomstertj) - Thursday, 13 April 2017, 22:13 GMT
I'm getting this problem too. Logically I'd think grub-mkconfig would put "linux" as the default entry (0) and "linux-lts" in the Advanced section so if "linux" breaks something you can try "linux-lts." Correct me if that is not how it's supposed to be; you could make the argument that "linux-lts" should be default because it may be more stable in some cases.

My GRUB version is: 1:2.02.rc2-1 which I assume means 2.02.rc2-1
Comment by Alif (alive4ever) - Monday, 17 April 2017, 08:09 GMT
I think the menu order doesn't matter, since the default kernel to be booted can be configured via "GRUB_DEFAULT".

The default Arch Linux installation doesn't pull 'linux-lts'.
If a user installs linux-lts manually, it's assumed that the user wants to boot linux-lts and grub-mkconfig does that.

Comment by vlamnire0 (blomstertj) - Monday, 17 April 2017, 18:48 GMT

I completely see what you're saying; however, I need the "GRUB_DEFAULT" line set to "saved" or the "grub-reboot" command does not work correctly. I do understand though that not many people are probably using this command.
Comment by AMM (amish) - Tuesday, 06 June 2017, 18:02 GMT
I disagree with Alif. If user installs linux-lts it does not necessarily mean that user wants to boot linux-lts

Most user install linux-lts as fallback just incase linux boot fails.

Plus arch philosophy is of always being up-to-date with latest version and hence having linux should be the preferred kernel.
Comment by freswa (frederik) - Wednesday, 12 February 2020, 12:23 GMT
Is this still an issue?
Comment by Fausto Filho (ffilho) - Sunday, 19 April 2020, 05:49 GMT
Affirmative, freswa. I've been trough it - actually i'm going under this issue right now. Things get more serious while using full disk encryption, when 'saved' option to GRUB_DEFAULT won't work due LVM and LUKS. I was planning to create a pacman hook to manipulate grub.cfg before getting in here. Gonna test this fix and share the results with you guys.
Comment by Fausto Filho (ffilho) - Monday, 20 April 2020, 15:14 GMT
Affirmative, freswa. I've been trough it - actually i'm going under this issue right now. Things get more serious while using full disk encryption, when 'saved' option to GRUB_DEFAULT won't work due LVM and LUKS. I was planning to create a pacman hook to manipulate grub.cfg before getting in here. Gonna test this fix and share the results with you guys.
Comment by Fausto Filho (ffilho) - Wednesday, 22 April 2020, 00:20 GMT
After aplying the fix suggest by magicrhesus I have now linux, linux fallback, linux-lts, linux-lts fallback, generated in this specific order by running grub-mkconfig command using the modified mkconfig_lib file.
Using the pristine mkconfig_lib config file I always ended with lts on top of linux, which isn't a good deal since I would like to have those in the opposite order.
It's nice to say that on current arch versions, grub-mkconfig_lib is now located on /usr/share/grub/ and no more on /usr/lib/grub/ as shown on the proposed patch.
Here's my cent over this issue: a new patch file (I keep the original content commented in case anyone want to check on it).
Thanks to everyone involved on this. Cheers!
Comment by Chigozirim Chukwu (FirstAirBender) - Wednesday, 04 November 2020, 05:12 GMT




After reviewing my options and reading a bit about grub (https://www.dedoimedo.com/computers/grub-2.html),
I decided against modifying grub specific files. I think it's better to modify your /etc/grub.d/10_linux script.

Around line 198 in the script, I found:
linux=`version_find_latest $list`

Using the currently popular suggestion in this thread, I changed the line to:
linux=`echo $list | tr ' ' '\n' | sort -V | head -1 | cat`

And that seems to have worked!

I think this approach of modifying the script may actually be a better approach, than changing the way grub orders kernels because of Arch-specific naming conventions.
Comment by Sourav Das (souravdas142) - Thursday, 24 December 2020, 08:38 GMT
suggestion by Chigozirim Chukwu (FirstAirBender) gives wonderful result thanks a lot man.
Comment by allexj (allexj) - Monday, 23 August 2021, 06:40 GMT
the issue is still there
Comment by Chris Mowley (mowley) - Tuesday, 14 September 2021, 00:55 GMT
The issue is still here, I've gone with applying the patch
Comment by Paolo Mainardi (paolomainardi) - Sunday, 14 November 2021, 17:47 GMT
Stumbled upon the same issue, just subscribing to the notifications of this thread.
Comment by Sourav Das (souravdas142) - Thursday, 02 December 2021, 14:14 GMT
@all The solution is already given by @FirstAirBender
please edit `/etc/grub.d/10_linux. according to the patch or directly apply it.
No need to flood with comments. If something agan not working then may be `pacman`
replaces `/etc/grub.d/10_linux` with a new file. just apply it again. I'm still using the
same with success.

diff --git a/etc/grub.d/10_linux b/10_linux
index 81c8415..22402c3 100755
--- a/etc/grub.d/10_linux
+++ b/10_linux
@@ -197,7 +197,16 @@ submenu_indentation=""

while [ "x$list" != "x" ] ; do
- linux=`version_find_latest $list`
+ # linux=`version_find_latest $list`
+ # If you want `linux` should boot by default and `linux-lts`
+ # is fallback, uncomment below line. You can use differnet
+ # sorting technique to change sorting behaviour, see `man sort`
+ # For more, see at https://bugs.archlinux.org/task/28081 on archive.org
+ # linux=`echo $list | tr ' ' '\n' | sort -V | head -1 | cat`
+ linux=`echo $list | tr ' ' '\n' | sort -Vr | head -1 | cat`
gettext_printf "Found linux image: %s\n" "$linux" >&2
basename=`basename $linux`
dirname=`dirname $linux`
Comment by Buggy McBugFace (bugbot) - Tuesday, 08 August 2023, 19:11 GMT
This is an automated comment as this bug is open for more then 2 years. Please reply if you still experience this bug otherwise this issue will be closed after 1 month.
Comment by Jendrik (corvus_192) - Saturday, 21 October 2023, 14:01 GMT
Issue is still present.