diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in index 301d1ac22..fa3de6008 100644 --- a/util/grub-mkconfig_lib.in +++ b/util/grub-mkconfig_lib.in @@ -204,16 +204,16 @@ version_sort () { case $version_sort_sort_has_v in yes) - LC_ALL=C sort -V;; + LC_ALL=C sort -V "$@";; no) - LC_ALL=C sort -n;; + LC_ALL=C sort -n "$@";; *) if sort -V /dev/null 2>&1; then version_sort_sort_has_v=yes - LC_ALL=C sort -V + LC_ALL=C sort -V "$@" else version_sort_sort_has_v=no - LC_ALL=C sort -n + LC_ALL=C sort -n "$@" fi;; esac } diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in index b4a4d6900..c6a1ec935 100644 --- a/util/grub.d/10_linux.in +++ b/util/grub.d/10_linux.in @@ -195,9 +195,15 @@ title_correction_code= # yet, so it's empty. In a submenu it will be equal to '\t' (one tab). submenu_indentation="" +# Perform a reverse version sort on the entire list. +# Temporarily replace the '.old' suffix by ' 1' and append ' 2' for all +# other files to order the '.old' files after their non-old counterpart +# in reverse-sorted order. + +reverse_sorted_list=$(echo $list | tr ' ' '\n' | sed -e 's/\.old$/ 1/; / 1$/! s/$/ 2/' | version_sort -r | sed -e 's/ 1$/.old/; s/ 2$//') + is_top_level=true -while [ "x$list" != "x" ] ; do - linux=`version_find_latest $list` +for linux in ${reverse_sorted_list}; do gettext_printf "Found linux image: %s\n" "$linux" >&2 basename=`basename $linux` dirname=`dirname $linux` @@ -295,8 +301,6 @@ while [ "x$list" != "x" ] ; do linux_entry "${OS}" "${version}" recovery \ "${GRUB_CMDLINE_LINUX_RECOVERY} ${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