tests/util/grub-shell-luks-tester: Find cryptodisk by UUID

GRUB has the capability to search all the disks for a cryptodisk of a
given UUID. Use this instead of hardcoding which disk is the cryptodisk,
which can change when devices are added or removed, or potentially when
QEMU is upgraded. This can not be done for the detached header tests
because the header contains the UUID.

Also, capitalize comment lines for consistency.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
This commit is contained in:
Glenn Washburn authored and Daniel Kiper committed 2025-03-26 14:08:49 +01:00
1 parent 3fd163e453
commit bb6d3199b3
1 file changed
+16 -19
+16 -19
View File
@@ -30,6 +30,7 @@ PATH="${builddir}:$PATH"
export PATH export PATH
grub_shell_opts= grub_shell_opts=
disk=
disksize=20M disksize=20M
detached_header= detached_header=
keyfile= keyfile=
@@ -68,18 +69,6 @@ EOF
. "${builddir}/grub-core/modinfo.sh" . "${builddir}/grub-core/modinfo.sh"
# TODO: We should be selecting the drive based on disk id, change this once
# grub support searching by disk id.
disk="hd0"
case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in
i386-qemu)
disk="ata0"
;;
loongarch64-efi)
disk="hd1"
;;
esac
# Check the arguments. # Check the arguments.
for option in "$@"; do for option in "$@"; do
case "$option" in case "$option" in
@@ -158,7 +147,7 @@ get_random_bytes() {
| tr -d '\0' | dd bs=1 count=$(($NUM_BYTES)) 2>/dev/null | tr -d '\0' | dd bs=1 count=$(($NUM_BYTES)) 2>/dev/null
} }
# create a random directory to be hold generated files # Create a random directory to be hold generated files
lukstestdir="`mktemp -d "${TMPDIR:-/tmp}/$(basename "$0").XXXXXXXXXX"`" || exit 20 lukstestdir="`mktemp -d "${TMPDIR:-/tmp}/$(basename "$0").XXXXXXXXXX"`" || exit 20
luksfile=$lukstestdir/luks.disk luksfile=$lukstestdir/luks.disk
lukshdrfile=$lukstestdir/luks.header lukshdrfile=$lukstestdir/luks.header
@@ -185,14 +174,21 @@ if [ -n "$detached_header" ]; then
csopts="$csopts --header $lukshdrfile" csopts="$csopts --header $lukshdrfile"
fi fi
# create the key file # Create the key file
echo -n "$password" > $lukskeyfile echo -n "$password" > $lukskeyfile
# Create a very small LUKS container for the test # Create a very small LUKS container for the test
truncate -s $disksize $luksfile || exit 21 truncate -s $disksize $luksfile || exit 21
# Format the luks disk file # Format the luks disk file
cryptsetup luksFormat -q $csopts $luksfile $lukskeyfile || exit 22 cryptsetup luksFormat -q $csopts ${luksfile} ${lukskeyfile} || exit 22
if [ -z "$detached_header" ]; then
cryptomount_opts="$cryptomount_opts -u $(cryptsetup luksUUID ${luksdiskfile})"
elif [ -z "$disk" ]; then
# In detached header mode, so must pass the disk to cryptomount.
# Is this always correct?
disk=hd0
fi
# Run any cryptsetup scripts # Run any cryptsetup scripts
export luksdiskfile export luksdiskfile
@@ -264,7 +260,7 @@ fi
# Can not use --disk with a raw LUKS container because it appears qemu # Can not use --disk with a raw LUKS container because it appears qemu
# tries to convert the image to and is failing with: # tries to convert the image to and is failing with:
# "Parameter 'key-secret' is required for cipher" # "Parameter 'key-secret' is required for cipher"
qemuopts="$qemuopts -drive file=$luksfile,index=0,media=disk,format=raw" qemuopts="$qemuopts -drive file=$luksfile,media=disk,format=raw"
# Add crypto modules # Add crypto modules
modules="$modules cryptodisk luks luks2 fat" modules="$modules cryptodisk luks luks2 fat"
@@ -282,7 +278,8 @@ grub_keyfile_size="$keyfile_size"
vfilename="`basename $vfile`" vfilename="`basename $vfile`"
vtext="$vtext" vtext="$vtext"
trim_line="$trim_line" trim_line="$trim_line"
disk="$disk" disk="${disk:+($disk)}"
cryptomount_opts="$cryptomount_opts"
EOF EOF
# If testing keyfiles, do not use password variable # If testing keyfiles, do not use password variable
@@ -325,7 +322,7 @@ fi
cdisk=crypto0 cdisk=crypto0
if test -n "$grub_debug" -a "$grub_debug" -gt 0; then if test -n "$grub_debug" -a "$grub_debug" -gt 0; then
echo cmd: cryptomount $cryptomount_opts ($disk) echo cmd: cryptomount $cryptomount_opts $disk
echo -n "devices: " echo -n "devices: "
ls ls
fi fi
@@ -333,7 +330,7 @@ fi
if test -n "$grub_debug" -a "$grub_debug" -gt 1; then if test -n "$grub_debug" -a "$grub_debug" -gt 1; then
set debug=all set debug=all
fi fi
cryptomount $cryptomount_opts ($disk) cryptomount $cryptomount_opts $disk
ret="$?" ret="$?"
if test -n "$grub_debug" -a "$grub_debug" -eq 2; then if test -n "$grub_debug" -a "$grub_debug" -eq 2; then
set debug= set debug=