grub2/0304-10_linux.in-Check-if-petitboot-sysfs-has-a-valid-ver.patch
Javier Martinez Canillas 89b6faf012
Fix config file generation failing due invalid petitboot version value
Resolves: rhbz#1921479

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
2021-03-11 13:15:37 +01:00

68 lines
2.8 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Javier Martinez Canillas <javierm@redhat.com>
Date: Wed, 10 Mar 2021 12:50:15 +0100
Subject: [PATCH] 10_linux.in: Check if petitboot sysfs has a valid version
The script assumes that the petitboot sysfs entry contains a valid version
number, but this is not always the case. For example, on a Talos II system
a user reported that contained the following value:
$ cat /sys/firmware/devicetree/base/ibm,firmware-versions/petitboot
0ed84c0-p94177c1
This lead to the script wrongly trying to compare these hashes as if they
were integers values, which caused the following error when re-generating
the GRUB configuration file:
/etc/grub.d/10_linux: line 234: test: 0ed84c0-p94177c1: integer expression expected
/etc/grub.d/10_linux: line 235: test: 0ed84c0-p94177c1: integer expression expected
Check that the major and minor values are integers before attempting to do
the comparison. If these aren't numbers, then generate the menu with a set
of menuentry commands, since there's no way to know the petitboot version.
Resolves: rhbz#1921479
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
---
util/grub.d/10_linux.in | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in
index e61b6c94f11..b9426eb2e2e 100644
--- a/util/grub.d/10_linux.in
+++ b/util/grub.d/10_linux.in
@@ -223,20 +223,25 @@ if [ "x${GRUB_ENABLE_BLSCFG}" = "xtrue" ]; then
arch="$(uname -m)"
if [ "x${arch}" = "xppc64le" ] && [ -d /sys/firmware/opal ]; then
+ BLS_POPULATE_MENU="true"
petitboot_path="/sys/firmware/devicetree/base/ibm,firmware-versions/petitboot"
if test -e ${petitboot_path}; then
read -r -d '' petitboot_version < ${petitboot_path}
petitboot_version="$(echo ${petitboot_version//v})"
- major_version="$(echo ${petitboot_version} | cut -d . -f1)"
- minor_version="$(echo ${petitboot_version} | cut -d . -f2)"
- if test -z ${petitboot_version} || test ${major_version} -lt 1 || \
- test ${major_version} -eq 1 -a ${minor_version} -lt 8; then
- BLS_POPULATE_MENU="true"
+ if test -n ${petitboot_version}; then
+ major_version="$(echo ${petitboot_version} | cut -d . -f1)"
+ minor_version="$(echo ${petitboot_version} | cut -d . -f2)"
+
+ re='^[0-9]+$'
+ if [[ $major_version =~ $re ]] && [[ $minor_version =~ $re ]] &&
+ ([[ ${major_version} -gt 1 ]] ||
+ [[ ${major_version} -eq 1 &&
+ ${minor_version} -ge 8 ]]); then
+ BLS_POPULATE_MENU="false"
+ fi
fi
- else
- BLS_POPULATE_MENU="true"
fi
fi