Bug 1124074 - grub2-mkconfig wrong sorting
Summary: grub2-mkconfig wrong sorting
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: grub2
Version: 7.2
Hardware: Unspecified
OS: Linux
urgent
urgent
Target Milestone: rc
: ---
Assignee: rmarshall
QA Contact: Release Test Team
Petr Bokoc
URL:
Whiteboard:
: 1154430 1260555 (view as bug list)
Depends On:
Blocks: 1205794 1133060 1229329
TreeView+ depends on / blocked
 
Reported: 2014-07-28 23:21 UTC by amit yadav
Modified: 2019-08-15 03:55 UTC (History)
31 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Improved sorting of GRUB2 boot menu An issue with the sorting mechanism used by the "grub2-mkconfig" command could cause the grub.cfg configuration file to be generated with available kernels sorted incorrectly. GRUB2 now uses the _rpmdevtools_ package to sort available kernels and the configuration file is being generated correctly with the most recent kernel version listed at the top.
Clone Of:
: 1229329 1249668 (view as bug list)
Environment:
Last Closed: 2015-11-19 12:23:28 UTC


Attachments (Terms of Use)
Workaround patch for version sorting (733 bytes, patch)
2014-12-08 23:52 UTC, Nathan G. Grennan
no flags Details | Diff


Links
System ID Priority Status Summary Last Updated
Red Hat Product Errata RHSA-2015:2401 normal SHIPPED_LIVE Low: grub2 security, bug fix, and enhancement update 2015-11-19 11:00:33 UTC
Red Hat Knowledge Base (Solution) 1145853 None None None Never

Description amit yadav 2014-07-28 23:21:02 UTC
Description of problem:
"grub2-mkconfig" command is not sorting kernel menu entries in proper order.

Version-Release number of selected component (if applicable): 
grub2-2.02-0.2.10.el7.x86_64

How reproducible:
Always

Steps to Reproduce:

1. Install multiple kernels on RHEL7 and check default grub.cfg file 
2. run "grub2-mkconfig -o /boot/grub2/grub.cfg
3. Now check the order of kernel menuentry in /boot/grub2/grub.cfg

   #  grub2-mkconfig | grep menuentry


Actual results:

menuentry 'Red Hat Enterprise Linux Server, with Linux 3.10.0-123.el7.x86_64' --class red --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-123.el7.x86_64-advanced-c2dcadd7-fdd1-4d7d-aeb4-6ff2e3802b36' {
Found linux image: /boot/vmlinuz-3.10.0-123.4.4.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-123.4.4.el7.x86_64.img
menuentry 'Red Hat Enterprise Linux Server, with Linux 3.10.0-123.4.4.el7.x86_64' --class red --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-123.4.4.el7.x86_64-advanced-c2dcadd7-fdd1-4d7d-aeb4-6ff2e3802b36' {
Found linux image: /boot/vmlinuz-3.10.0-123.4.2.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-123.4.2.el7.x86_64.img
menuentry 'Red Hat Enterprise Linux Server, with Linux 3.10.0-123.4.2.el7.x86_64' --class red --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-123.4.2.el7.x86_64-advanced-c2dcadd7-fdd1-4d7d-aeb4-6ff2e3802b36' {
Found linux image: /boot/vmlinuz-0-rescue-31774a1cc2a54819ab51e1d81bb9dac7
Found initrd image: /boot/initramfs-0-rescue-31774a1cc2a54819ab51e1d81bb9dac7.img


Expected results:
Latest kernel entries should come first in /boot/grub2/grub.cfg.

Additional info:
There issue is already report in Fedora(fixed) bug : https://bugzilla.redhat.com/show_bug.cgi?id=678840

Comment 2 Adam Miller 2014-09-18 21:47:59 UTC
I'm seeing this behavior as well. After updating/installing the latest kernel and rebooting I still see the following output from yum:

Security: kernel-3.10.0-123.6.3.el7.x86_64 is an installed security update
Security: kernel-3.10.0-123.el7.x86_64 is the currently running version

The work around described here seems to work:
https://access.redhat.com/solutions/1145853

Comment 3 bugreports2005 2014-10-10 06:25:20 UTC
Not sure about the workaround, I thought that the sort fails because the "e" of "el7" in "123.el7.x86_64" wins over numbers when compared to the three-level deep revisions of the latter kernels.

The comparison is version_test_gt() in /usr/share/grub/grub-mkconfig_lib, and at least this quick modification that simply crops off from .el7 appeared to result in correct ordering:

version_test_gt_a="`echo "$1" | sed -e "s/[^-]*-//" -e "s/\.el[0-9].*//"`"
version_test_gt_b="`echo "$2" | sed -e "s/[^-]*-//" -e "s/\.el[0-9].*//"`"

Comment 4 Nicholas, Crawford 2014-10-19 16:37:15 UTC
potentially related https://bugzilla.redhat.com/show_bug.cgi?id=1154430

Comment 5 Nathan G. Grennan 2014-12-08 23:52:18 UTC
The problem is .x86_64 on the end. I created a patch that works around this issue. I tested it actual numbers 123, 123.6.3, and 123.9.3. I also tested it with actual numbers and made up numbers like 122 and 124. It does the right thing in both cases.

I also formatted my patch be friendly with adding the the src.rpm.

Comment 6 Nathan G. Grennan 2014-12-08 23:52:49 UTC
Created attachment 966036 [details]
Workaround patch for version sorting

Comment 7 Peter Jones 2014-12-15 16:37:34 UTC
*** Bug 1154430 has been marked as a duplicate of this bug. ***

Comment 9 Nathan G. Grennan 2014-12-16 19:53:25 UTC
This bug also affects Fedora 21. It is just that Fedora has stuck to simpler/shorter release numbers for kernel packages. I made a custom kernel, kernel-core-3.17.6-300.11.fc21.x86_64, based on kernel-core-3.17.6-300.fc21.x86_64. It has the same issue with grub2.

Comment 10 Plamen Totev 2015-01-04 15:43:11 UTC
The reason is that grub-mkconfig_lib user sort -V to compare the order of two versions and the GNU implementation does not recognizes suffixes that contain '_' such as x86_64. The bug is reported on the GRUB site - https://savannah.gnu.org/bugs/?42844 
I've provided more detailed explanation and patch there

Comment 18 Petr Bokoc 2015-08-18 15:54:56 UTC
Hi Robert, I have updated Doc Text to prepare it for 7.2 Beta Release Notes.

Please review the Doc Text field and let me know whether it's correct or if there's anything you would like to add or change.

Comment 19 Petr Janda 2015-09-01 09:09:52 UTC
reproduced on RHEL-7.1 with grub2-tools-2.02-0.16.el7.x86_64
verified with grub2-tools-2.02-0.25.el7.x86_64 from RHEL-7.2-20150820.0

Comment 20 rmarshall 2015-09-01 13:52:25 UTC
Petr Bokoc - Doc Text looks fine to me.

Comment 25 rmarshall 2015-10-12 18:34:44 UTC
*** Bug 1260555 has been marked as a duplicate of this bug. ***

Comment 26 errata-xmlrpc 2015-11-19 12:23:28 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://rhn.redhat.com/errata/RHSA-2015-2401.html


Note You need to log in before you can comment on or make changes to this bug.