kickstart functions: Fix empty variable check

This commit fixes two empty variable checks in the get_disk_dev function
in the kickstart shell functions. The "[" helper's "-n" operator needs
an argument to be able to detect whether the argument is an empty string
or not. When $disk is an empty shell variable, then '[ -n $disk ]' will
return zero (i.e., true). The correct way to check for the empty string
is to double-quote the variable; i.e., '[ -n "$disk" ]'.

The impact of this bug was observed with the v5.10 kernel, because the
v5.10 kernel uses the device node "sda" for USB storage in some
configurations, whereas the legacy v3.10 kernel always made "sda" the
first non-USB (i.e., internal) storage unit. A USB-based "sda" would
result in an empty $disk value, which would incorrectly be detected as a
non-empty variable due to the bug fixed by this commit. This in turn
would result in an installation failure due to the inability to find the
first non-USB storage unit on the system. For future reference, the
error messages were as follows:

"""
There was an error running the kickstart script at line 429. This is a
fatal error and installation will be aborted. The details of this error
are:
2021-10-09 08:12:45.716 - ISO_DEV=''.
2021-10-09 08:12:45.716 - USB_DEV=''.
readlink: missing operand
Try 'readlink --help' for more information.
readlink: missing operand
Try 'readlink --help' for more information.
2021-10-09 08:12:45.735 - Found rootfs on: ->.
readlink: missing operand
Try 'readlink --help' for more information.
readlink: missing operand
Try 'readlink --help' for more information.
2021-10-09 08:12:45.747 - Found boot on: ->.

Installation failed.

ERROR: Specified installation () or boot () device is invalid.

Pane is dead
"""

Verification:
- Installation of an ISO prepared with this patch and a v5.10 kernel
  works as expected on a system with a USB drive attached.

Closes-Bug: #1950163

Change-Id: Iee6a6bfb79b80df68f888f2eb498ec2cdbae6147
Signed-off-by: M. Vefa Bicakci <vefa.bicakci@windriver.com>
This commit is contained in:
M. Vefa Bicakci 2021-11-07 11:07:38 -05:00
parent 0551c665cb
commit 46bc928ce6
1 changed files with 4 additions and 4 deletions

View File

@ -87,8 +87,8 @@ function get_disk_dev()
for blk_dev in vda vdb sda sdb dda ddb hda hdb; do
if [ -d /sys/block/\$blk_dev ]; then
disk=\$(ls -l /sys/block/\$blk_dev | grep -v usb | head -n1 | sed 's/^.*\([vsdh]d[a-z]\+\).*$/\1/');
if [ -n \$disk ]; then
echo \$disk
if [ -n "\$disk" ]; then
echo "\$disk"
return
fi
fi
@ -96,8 +96,8 @@ function get_disk_dev()
for blk_dev in nvme0n1 nvme1n1; do
if [ -d /sys/block/\$blk_dev ]; then
disk=\$(ls -l /sys/block/\$blk_dev | grep -v usb | head -n1 | sed 's/^.*\(nvme[01]n1\).*$/\1/');
if [ -n \$disk ]; then
echo \$disk
if [ -n "\$disk" ]; then
echo "\$disk"
return
fi
fi