From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1XQiHd-00011w-A7 for mharc-grub-devel@gnu.org; Sun, 07 Sep 2014 15:37:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39000) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XQiHX-00010v-2H for grub-devel@gnu.org; Sun, 07 Sep 2014 15:37:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XQiHR-0004zJ-UA for grub-devel@gnu.org; Sun, 07 Sep 2014 15:37:51 -0400 Received: from mail.doug-brunner.com ([54.187.162.22]:33082) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XQiHR-0004wa-KI for grub-devel@gnu.org; Sun, 07 Sep 2014 15:37:45 -0400 Received: from [192.168.1.5] (24-205-76-133.dhcp.psdn.ca.charter.com [24.205.76.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) (Authenticated sender: doug@doug-brunner.com) by mail.doug-brunner.com (Postfix) with ESMTPSA id 4793F83C4A for ; Sun, 7 Sep 2014 19:37:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=doug-brunner.com; s=mail; t=1410118646; bh=IwP9bIJZscF1xjW6N58nMECUJC9Zq6ijD639rCLtv5c=; h=Date:From:To:Subject:From; b=bD2weUXb8OHk4NTzmS2y/kC3p3GuCN6PFxZruPX3GF8iK41iFaC6dCDPvwLSq2IBU wEeNJB4FDE1YUFEUAWYAg5pNKl+183vG5nGw6Uc6B6kNscICVYGrAoWDKbxxgdac6D NIt8DGDl7o8MUGOZ+tInauFE5K+r4Wy76VngYch8= Message-ID: <540CB400.2060004@doug-brunner.com> Date: Sun, 07 Sep 2014 12:37:36 -0700 From: Doug Brunner User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.0 MIME-Version: 1.0 To: grub-devel@gnu.org Subject: [PATCH] Add config option to prefer Linux kernel versions by substring match Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 54.187.162.22 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 07 Sep 2014 19:37:56 -0000 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 se= t to prioritize Linux kernels containing a given substring. This takes precedence over version ordering, so if you h= ave 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 e= rror-prone: you have to figure out where in the GRUB menu it will appear, then enter that in /etc/default/grub, and if th= e 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 add= ing kernels Signed-off-by: Doug Brunner --- 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 =20 if test "x${grub_cfg}" !=3D "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=3D # yet, so it's empty. In a submenu it will be equal to '\t' (one tab). submenu_indentation=3D"" =20 +pref_list=3D"" +non_pref_list=3D"" +for entry in $list; do + if [[ "$entry" =3D=3D *$GRUB_LINUX_PREF_VERSION_SUBSTR* ]]; then + pref_list=3D"$pref_list $entry" + else + non_pref_list=3D"$non_pref_list $entry" + fi +done + is_top_level=3Dtrue -while [ "x$list" !=3D "x" ] ; do - linux=3D`version_find_latest $list` +while [ "x$pref_list$non_pref_list" !=3D "x" ] ; do + if [ "x$pref_list" !=3D "x" ]; then + linux=3D`version_find_latest $pref_list` + pref_list=3D`echo $pref_list | tr ' ' '\n' | fgrep -vx "$linux" | tr= '\n' ' '` + else + linux=3D`version_find_latest $non_pref_list` + non_pref_list=3D`echo $non_pref_list | tr ' ' '\n' | fgrep -vx "$lin= ux" | tr '\n' ' '` + fi gettext_printf "Found linux image: %s\n" "$linux" >&2 basename=3D`basename $linux` dirname=3D`dirname $linux` @@ -240,8 +256,6 @@ while [ "x$list" !=3D "x" ] ; do linux_entry "${OS}" "${version}" recovery \ "single ${GRUB_CMDLINE_LINUX}" fi - - list=3D`echo $list | tr ' ' '\n' | fgrep -vx "$linux" | tr '\n' ' '` done =20 # If at least one kernel was found, then we need to