From: Glenn Washburn <development@efficientek.com>
To: grub-devel@gnu.org, Daniel Kiper <dkiper@net-space.pl>
Cc: Glenn Washburn <development@efficientek.com>
Subject: [PATCH] tests/util/grub-shell-luks-tester: Find cryptodisk by UUID
Date: Thu, 6 Mar 2025 00:18:43 -0600 [thread overview]
Message-ID: <20250306061843.3391672-1-development@efficientek.com> (raw)
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>
---
tests/util/grub-shell-luks-tester.in | 35 +++++++++++++---------------
1 file changed, 16 insertions(+), 19 deletions(-)
diff --git a/tests/util/grub-shell-luks-tester.in b/tests/util/grub-shell-luks-tester.in
index abb0013e4387..aa454d136a22 100644
--- a/tests/util/grub-shell-luks-tester.in
+++ b/tests/util/grub-shell-luks-tester.in
@@ -30,6 +30,7 @@ PATH="${builddir}:$PATH"
export PATH
grub_shell_opts=
+disk=
disksize=20M
detached_header=
keyfile=
@@ -70,18 +71,6 @@ EOF
. "${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.
for option in "$@"; do
case "$option" in
@@ -163,7 +152,7 @@ get_random_bytes() {
| 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
luksfile=$lukstestdir/luks.disk
lukshdrfile=$lukstestdir/luks.header
@@ -190,14 +179,21 @@ if [ -n "$detached_header" ]; then
csopts="$csopts --header $lukshdrfile"
fi
-# create the key file
+# Create the key file
echo -n "$password" > $lukskeyfile
# Create a very small LUKS container for the test
truncate -s $disksize $luksfile || exit 21
# 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
export luksdiskfile
@@ -269,7 +265,7 @@ fi
# Can not use --disk with a raw LUKS container because it appears qemu
# tries to convert the image to and is failing with:
# "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
modules="$modules cryptodisk luks luks2 fat"
@@ -287,7 +283,8 @@ grub_keyfile_size="$keyfile_size"
vfilename="`basename $vfile`"
vtext="$vtext"
trim_line="$trim_line"
-disk="$disk"
+disk="${disk:+($disk)}"
+cryptomount_opts="$cryptomount_opts"
EOF
# If testing keyfiles, do not use password variable
@@ -330,7 +327,7 @@ fi
cdisk=crypto0
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: "
ls
fi
@@ -338,7 +335,7 @@ fi
if test -n "$grub_debug" -a "$grub_debug" -gt 1; then
set debug=all
fi
-cryptomount $cryptomount_opts ($disk)
+cryptomount $cryptomount_opts $disk
ret="$?"
if test -n "$grub_debug" -a "$grub_debug" -eq 2; then
set debug=
--
2.34.1
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
next reply other threads:[~2025-03-06 6:19 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-06 6:18 Glenn Washburn [this message]
2025-03-10 14:26 ` [PATCH] tests/util/grub-shell-luks-tester: Find cryptodisk by UUID Daniel Kiper
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250306061843.3391672-1-development@efficientek.com \
--to=development@efficientek.com \
--cc=dkiper@net-space.pl \
--cc=grub-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.