bugGNU GRUB - Bugs: bug #42597, Alpha sorting for kernel names...


You are not allowed to post comments on this tracker with your current authentication level.

bug #42597: Alpha sorting for kernel names without versions (rolling release)

Submitter:  Troy Engel <troyengel>
Submitted:  Sun 22 Jun 2014 05:32:44 PM UTC
Category:  User Interface Severity:  Major
Priority:  5 - Normal Item Group:  Feature Request
Status:  None Privacy:  Public
Assigned to:  None Originator Name: 
Open/Closed:  Open Release:  2.02~beta1
Release:  Reproducibility:  Every Time
Planned Release:  2.03+

Wed 31 Jan 2018 02:15:41 AM UTC, comment #1: 

wrong sort in version_test_numeric().

I installed different kernels under arch linux. A grub-mkconfig ordered the menu entries oddly.
As arch is not using versioning numbers in the kernel image's filenames, it should sort alphabetically.


the lts entry somehow always was sorted out as "newest". But it should be following order hardened, lts, zen.

I found a typo in grub-mkconfig_lib.in line 233:
if (echo "$version_test_numeric_a" ; echo "$version_test_numeric_b") | version_sort | head -n 1 | grep -qx "$version_test_numeric_b" ; then

It should be
....... | grep -qx "$version_test_numeric_a" ; then

After that fix the ordering is correct in my case.

(file #43128)

Sir Grublon <grublon>
Sun 22 Jun 2014 05:32:44 PM UTC, original submission:  

The /etc/grub.d/10_linux design is based around the expectation that kernel names in /boot will contain version numbers, allowing the newest version to sort to the top and become the default entry. For systems like Fedora/Red Hat/CentOS this works fine.

For rolling release distros like Arch, this causes the last entry in the found list to become the default. For example, if you install the "linux" and "linux-lts" kernels the natural find order in 10_linux is "linux linux-lts".

The callout to version_find_latest results in returning "linux-lts" due to how the code works in grub-mkconfig_lib and specifically version_sort_numeric here:

  if (echo "$version_test_numeric_a" ; echo "$version_test_numeric_b") | version_sort | head -n 1 | grep -qx "$version_test_numeric_b" ; then
    return 0
    return 1

Attached is my attempt at a basic patch that checks the string of kernels found and if there are no numerics present in them, default to popping them off the stack in order found (natural alpha sort from the "for i in..." code previously).

  if [ $(echo $list | grep -q '[0-9]') ]; then
    linux=`version_find_latest $list`

There is probably a better way to do this, but this simple hack works for the basic Arch install to allow "linux" to be the expected default, leaving "linux-lts" to be available for emergency purposes.

Troy Engel <troyengel>


(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attached Files
file #43128:  grub.patch added by grublon (576B - text/x-patch - typo fix in version_test_numeric() - fix alphabetical sorting problem)
file #31596:  10_linux_noversion.patch added by troyengel (728B - text/x-patch - Patch to check for versions in kernel name first)


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by tyilo
  • -email is unavailable- added by grublon (Updated the item)
  • -email is unavailable- added by phcoder (Updated the item)
  • -email is unavailable- added by troyengel (Submitted the item)

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.


    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-02-25 tyilo Carbon-Copy- Added -email is unavailable-
    2018-01-31 grublon Attached File- Added grub.patch, #43128
    2016-03-02 phcoder Planned ReleaseNone 2.03+
    2014-06-22 troyengel Attached File- Added 10_linux_noversion.patch, #31596

    Back to the top

    Powered by Savane 3.13-12ab.
    Corresponding source code