From ba75e3e60a9f638f7f36dba569ce32b543a1fad7 Mon Sep 17 00:00:00 2001 From: "Andrew J. Hesford" Date: Fri, 1 Dec 2023 12:00:35 -0500 Subject: [PATCH] testing: quality-of-life improvements - Pre-build EFI executables in each distribution when possible - Prefer running the EFI executable if one exists - Allow selection of pre-built per-distribution images when running --- testing/helpers/chroot-void.sh | 2 +- testing/helpers/configure-debian.sh | 3 + testing/helpers/pool-setup.sh | 6 +- testing/helpers/zbm-populate.sh | 7 ++ testing/run.sh | 101 +++++++++++++++++++++------- 5 files changed, 92 insertions(+), 27 deletions(-) diff --git a/testing/helpers/chroot-void.sh b/testing/helpers/chroot-void.sh index 6174e65a9..d8fb4946c 100755 --- a/testing/helpers/chroot-void.sh +++ b/testing/helpers/chroot-void.sh @@ -69,7 +69,7 @@ sed -i 's/^#PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config # Pre-install zfsbootmenu if [ -x /root/zbm-populate.sh ]; then xbps-query -Rp run_depends zfsbootmenu | xargs xbps-install -y - xbps-install -y git + xbps-install -y git gummiboot-efistub SKIP_PERL=yes /root/zbm-populate.sh rm /root/zbm-populate.sh fi diff --git a/testing/helpers/configure-debian.sh b/testing/helpers/configure-debian.sh index 735dd238d..307e590d7 100755 --- a/testing/helpers/configure-debian.sh +++ b/testing/helpers/configure-debian.sh @@ -11,6 +11,9 @@ echo 'root:zfsbootmenu' | chpasswd -c SHA256 if [ -x /root/zbm-populate.sh ]; then apt-get install --yes --no-install-recommends \ git dracut-core fzf kexec-tools cpanminus gcc make + if [[ "$0" =~ "debian" ]]; then + apt-get install --yes --no-install-recommends systemd-boot-efi + fi /root/zbm-populate.sh rm /root/zbm-populate.sh fi diff --git a/testing/helpers/pool-setup.sh b/testing/helpers/pool-setup.sh index 27bc66076..73ca1a301 100755 --- a/testing/helpers/pool-setup.sh +++ b/testing/helpers/pool-setup.sh @@ -206,16 +206,16 @@ fi # Pre-populate the test environment with ZBM from the testbed if [ -d "${CHROOT_MNT}/zfsbootmenu" ]; then if chroot "${CHROOT_MNT}" /usr/bin/generate-zbm --prefix vmlinuz; then - for f in vmlinuz-bootmenu initramfs-bootmenu.img; do + for f in vmlinuz-bootmenu initramfs-bootmenu.img vmlinuz.EFI; do file="${CHROOT_MNT}/zfsbootmenu/build/${f}" [ -f "${file}" ] || continue if [ -d "${TESTDIR}" ]; then - mv "${file}" "${TESTDIR}/${f}.${DISTRO}" + cp "${file}" "${TESTDIR}/${f}.${DISTRO}" chmod 644 "${TESTDIR}/${f}.${DISTRO}" if [ ! -e "${TESTDIR}/${f}" ] || [ -L "${TESTDIR}/${f}" ]; then - ln -sf "${f}.${DISTRO}" "${TESTDIR}/${f}" + ln -Tsf "${f}.${DISTRO}" "${TESTDIR}/${f}" fi fi done diff --git a/testing/helpers/zbm-populate.sh b/testing/helpers/zbm-populate.sh index 2bf094cfc..34f4510e5 100755 --- a/testing/helpers/zbm-populate.sh +++ b/testing/helpers/zbm-populate.sh @@ -16,6 +16,13 @@ if [ -f /etc/zfsbootmenu/config.yaml ]; then -e 's@ImageDir:.*@ImageDir: /zfsbootmenu/build@' \ -e '/BootMountPoint:/d' -i /etc/zfsbootmenu/config.yaml + # Build the EFI executable if the stub is available + for stubdir in /usr/lib/gummiboot /usr/lib/systemd/boot/efi; do + [ -r "${stubdir}/linuxx64.efi.stub" ] || continue + sed -e 's/Enabled:.*/Enabled: true/' -i /etc/zfsbootmenu/config.yaml + break + done + case "${INITCPIO,,}" in yes|y|on|1) sed -e "s/InitCPIO:.*/InitCPIO: true/" -i /etc/zfsbootmenu/config.yaml diff --git a/testing/run.sh b/testing/run.sh index 046e9e435..0a2eb2d02 100755 --- a/testing/run.sh +++ b/testing/run.sh @@ -15,31 +15,67 @@ error() { } usage() { - cat < + Set kernel command line + + -A (May be repeated) + Append additional argument to kernel command line + + -C + Set the number of CPUs in the virtual machine + + -d (May be repeated) + Attach the specified disk image to the test VM + + -D + Boot the testbed contained in the given directory + + -M + Set the amount of memory in the virtual machine + + -o + Attempt to boot image for a specific distribution; + requires boot files with a "." extension + + -S + When creating EFI bundles, use the stub at the given path + + -v + Select the qemu display type + +FLAGS -f Force recreation of the initramfs - -s Enable serial console on stdio - -v Set type of qemu display to use - -D Set test directory - -c Enable dropbear remote access via crypt-ssh - -n Do not reset the controlling terminal after the VM exits - -e Boot the VM with an EFI bundle - -F Generate a flamegraph/flamechart using tracing data from ZBM - -E Enable early initramfs tracing + -i Use mkinitcpio to generate the testing initramfs + -B Use Busybox for mkinitcpio miser mode + -r Use Dracut to generate the testing initramfs + + -e Boot the VM with an EFI bundle + -p Boot the VM with the kernel/initramfs pair + + -E Enable early initramfs tracing + -F Generate a flamegraph/flamechart using tracing data from ZBM -G Enable debug output for generate-zbm - -M Set the amount of memory for the virtual machine - -C Set the number of CPUs for the virtual machine - -B Use Busybox for mkinitcpio miser mode - -S Use alternate EFI stub file at specified path + + -c Enable dropbear remote access via crypt-ssh + + -n Do not reset the controlling terminal after the VM exits + + -s Enable serial console on stdio + + -h Show this message and exit EOF } -CMDOPTS="D:A:a:d:fsv:hineS:M:C:FEGcrB" +CMDOPTS="a:A:C:d:D:M:o:S:v:fiBrepEFGcnsh" + # First-pass option parsing just looks for test directory while getopts "${CMDOPTS}" opt; do @@ -93,10 +129,11 @@ SERIAL=0 DISPLAY_TYPE= SSH_INCLUDE=0 RESET=1 -EFI=0 +EFI= GENZBM_FLAGS=() MISER=0 EFISTUB= +SUFFIX= FLAME=0 EARLY_TRACING=0 @@ -150,6 +187,9 @@ while getopts "${CMDOPTS}" opt; do *) echo "EFI bundles unsupported on $(uname -m)" ;; esac ;; + p) + EFI=0 + ;; S) EFISTUB="$( realpath -e "${OPTARG}" )" ;; @@ -180,6 +220,9 @@ while getopts "${CMDOPTS}" opt; do B) MISER=1 ;; + o) + SUFFIX=".${OPTARG}" + ;; *) ;; esac @@ -361,18 +404,30 @@ if ((INITCPIO)) && ((MISER)); then EOF fi +# Image files the testbed may need to boot +BUNDLE="${TESTDIR}/vmlinuz.EFI${SUFFIX}" +KERNEL="${TESTDIR}/vmlinuz-bootmenu${SUFFIX}" +INITRD="${TESTDIR}/initramfs-bootmenu.img${SUFFIX}" + +if [ -z "${EFI}" ]; then + # If an EFI option was not chosen, select a workable default + EFI=0 + [ -f "${BUNDLE}" ] && EFI=1 +fi + # Creation is required if either kernel or initramfs is missing if ((EFI)) ; then - BUNDLE="${TESTDIR}/vmlinuz.EFI" [ -f "${BUNDLE}" ] || CREATE=1 else - KERNEL="${TESTDIR}/vmlinuz-bootmenu" - [ -f "${KERNEL}" ] || CREATE=1 - INITRD="${TESTDIR}/initramfs-bootmenu.img" + [ -f "${KERNEL}" ] || CREATE=1 [ -f "${INITRD}" ] || CREATE=1 fi +if ((CREATE)) && [ -n "${SUFFIX}" ]; then + error "distribution-specific images do not exist and will not be created" +fi + if ((CREATE)) ; then yamlconf="${TESTDIR}/local.yaml"