]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
test(UEFI): add test case for UEFI boot
authorLaszlo Gombos <laszlo.gombos@gmail.com>
Wed, 22 Mar 2023 19:56:25 +0000 (19:56 +0000)
committerLaszlo Gombos <laszlo.gombos@gmail.com>
Wed, 14 Jun 2023 14:52:30 +0000 (10:52 -0400)
Include OVMF in containers if it is not already present.

.github/workflows/integration.yml
test/TEST-18-UEFI/Makefile [new file with mode: 0644]
test/TEST-18-UEFI/test-init.sh [new file with mode: 0755]
test/TEST-18-UEFI/test.sh [new file with mode: 0755]
test/container/Dockerfile-Debian
test/container/Dockerfile-Fedora-latest
test/container/Dockerfile-Gentoo
test/run-qemu

index 863466fe6d66f3a86a64a834e2b476eb7551a37e..e83d531796c9524660b20a085c3ed919a2cd647d 100644 (file)
@@ -35,6 +35,7 @@ jobs:
                         "15",
                         "16",
                         "17",
+                        "18",
                         "62",
                         "98",
                 ]
diff --git a/test/TEST-18-UEFI/Makefile b/test/TEST-18-UEFI/Makefile
new file mode 100644 (file)
index 0000000..2dcab81
--- /dev/null
@@ -0,0 +1 @@
+-include ../Makefile.testdir
diff --git a/test/TEST-18-UEFI/test-init.sh b/test/TEST-18-UEFI/test-init.sh
new file mode 100755 (executable)
index 0000000..03966d2
--- /dev/null
@@ -0,0 +1,23 @@
+#!/bin/sh
+
+export PATH=/usr/sbin:/usr/bin:/sbin:/bin
+
+[ -e /proc/self/mounts ] \
+    || (mkdir -p /proc && mount -t proc -o nosuid,noexec,nodev proc /proc)
+
+grep -q '^sysfs /sys sysfs' /proc/self/mounts \
+    || (mkdir -p /sys && mount -t sysfs -o nosuid,noexec,nodev sysfs /sys)
+
+grep -q '^devtmpfs /dev devtmpfs' /proc/self/mounts \
+    || (mkdir -p /dev && mount -t devtmpfs -o mode=755,noexec,nosuid,strictatime devtmpfs /dev)
+
+grep -q '^tmpfs /run tmpfs' /proc/self/mounts \
+    || (mkdir -p /run && mount -t tmpfs -o mode=755,noexec,nosuid,strictatime tmpfs /run)
+
+: > /dev/watchdog
+
+exec > /dev/console 2>&1
+
+echo "made it to the rootfs! Powering down."
+echo "dracut-root-block-success" | dd oflag=direct,dsync of=/dev/sdb
+poweroff -f
diff --git a/test/TEST-18-UEFI/test.sh b/test/TEST-18-UEFI/test.sh
new file mode 100755 (executable)
index 0000000..fabb6bc
--- /dev/null
@@ -0,0 +1,92 @@
+#!/bin/bash
+
+# shellcheck disable=SC2034
+TEST_DESCRIPTION="UEFI boot"
+
+# Linux kernel requirements
+# CONFIG_BLK_DEV_INITRD for initramfs
+# CONFIG_EFI_HANDOVER_PROTOCOL for ovmf (Open Virtual Machine Firmware)
+# CONFIG_SATA_AHCI for ahci.ko
+# CONFIG_BLK_DEV_SD for sd_mod.ko
+# CONFIG_SQUASHFS_ZLIB for squashfs.ko
+
+ovmf_code() {
+    for path in \
+        "/usr/share/OVMF/OVMF_CODE.fd" \
+        "/usr/share/edk2/x64/OVMF_CODE.fd" \
+        "/usr/share/edk2-ovmf/OVMF_CODE.fd" \
+        "/usr/share/qemu/ovmf-x86_64-4m.bin"; do
+        [[ -s $path ]] && echo -n "$path" && return
+    done
+}
+
+test_check() {
+    [[ -n "$(ovmf_code)" ]]
+}
+
+KVERSION="${KVERSION-$(uname -r)}"
+
+test_marker_reset() {
+    dd if=/dev/zero of="$TESTDIR"/marker.img bs=1MiB count=1
+}
+
+test_marker_check() {
+    grep -U --binary-files=binary -F -m 1 -q dracut-root-block-success -- "$TESTDIR"/marker.img
+    return $?
+}
+
+test_dracut() {
+    TEST_DRACUT_ARGS+=" --local --no-hostonly --no-early-microcode --add test --kver $KVERSION"
+
+    # shellcheck disable=SC2162
+    IFS=' ' read -a TEST_DRACUT_ARGS_ARRAY <<< "$TEST_DRACUT_ARGS"
+
+    "$basedir"/dracut.sh "$@" \
+        --kernel-cmdline "panic=1 oops=panic softlockup_panic=1 systemd.crash_reboot selinux=0 console=ttyS0,115200n81 $DEBUGFAIL" \
+        "${TEST_DRACUT_ARGS_ARRAY[@]}" || return 1
+}
+
+test_run() {
+    declare -a disk_args=()
+    declare -i disk_index=1
+    qemu_add_drive_args disk_index disk_args "$TESTDIR"/marker.img marker
+    qemu_add_drive_args disk_index disk_args "$TESTDIR"/squashfs.img root
+
+    test_marker_reset
+    "$testdir"/run-qemu "${disk_args[@]}" -net none \
+        -drive file=fat:rw:"$TESTDIR"/ESP,format=vvfat,label=EFI \
+        -global driver=cfi.pflash01,property=secure,value=on \
+        -drive if=pflash,format=raw,unit=0,file="$(ovmf_code)",readonly=on
+    test_marker_check || return 1
+}
+
+test_setup() {
+    # Create what will eventually be our root filesystem
+    "$basedir"/dracut.sh --local --no-hostonly --no-early-microcode --nofscks \
+        --tmpdir "$TESTDIR" --keep --modules "test-root" --include ./test-init.sh /sbin/init \
+        "$TESTDIR"/tmp-initramfs.root "$KVERSION" || return 1
+
+    mkdir -p "$TESTDIR"/dracut.*/initramfs/proc
+    mksquashfs "$TESTDIR"/dracut.*/initramfs/ "$TESTDIR"/squashfs.img -quiet -no-progress
+
+    mkdir -p "$TESTDIR"/ESP/EFI/BOOT
+
+    if [ -f "/usr/lib/gummiboot/linuxx64.efi.stub" ]; then
+        TEST_DRACUT_ARGS+=" --uefi-stub /usr/lib/gummiboot/linuxx64.efi.stub "
+    fi
+
+    mkdir -p "$TESTDIR"/ESP/EFI/BOOT
+    test_dracut \
+        --modules 'rootfs-block test' \
+        --kernel-cmdline 'root=/dev/sdc ro rd.skipfsck rootfstype=squashfs' \
+        --drivers 'ahci sd_mod squashfs' \
+        --uefi \
+        "$TESTDIR"/ESP/EFI/BOOT/BOOTX64.efi
+}
+
+test_cleanup() {
+    return 0
+}
+
+# shellcheck disable=SC1090
+. "$testdir"/test-functions
index d1bd3d9a8fb517938aaa387db2f74045a5ac4fbd..5002e1d7271ad9c6ca53d3156e387a3ed75f6a60 100644 (file)
@@ -41,6 +41,7 @@ RUN apt-get update -y -qq && apt-get upgrade -y -qq && DEBIAN_FRONTEND=nonintera
     nfs-kernel-server \
     ntfs-3g \
     open-iscsi \
+    ovmf \
     parted \
     pigz \
     pkg-config \
index 2668a8e1f11bd4819858b855302292c9974dec90..2ce397513e359bd2bd759e66948d01e3405b0c1a 100644 (file)
@@ -59,6 +59,7 @@ RUN dnf -y install --setopt=install_weak_deps=False \
     squashfs-tools \
     strace \
     sudo \
+    systemd-boot-unsigned \
     systemd-networkd \
     systemd-resolved \
     tar \
index 3a2d5826ff89070d5e99fa429ae11b756ca828ab..471dfb056673df7d02b5def8295d780224f80e3f 100644 (file)
@@ -1,5 +1,15 @@
 FROM docker.io/gentoo/portage:latest as portage
 
+# uefi stub in a separate builder
+FROM docker.io/gentoo/stage3 as efistub
+COPY --from=portage /var/db/repos/gentoo /var/db/repos/gentoo
+
+# systemd-boot
+RUN mkdir -p /etc/portage/package.accept_keywords && \
+    echo "sys-boot/systemd-boot" >> /etc/portage/package.accept_keywords/systemd-boot && \
+    echo '>=sys-apps/systemd-utils-251.10 boot' > /etc/portage/package.use/systemd-boot && \
+    emerge -qv sys-boot/systemd-boot
+
 # kernel and its dependencies in a separate builder
 FROM docker.io/gentoo/stage3:musl as kernel
 COPY --from=portage /var/db/repos/gentoo /var/db/repos/gentoo
@@ -9,6 +19,7 @@ FROM docker.io/gentoo/stage3:musl
 COPY --from=portage /var/db/repos/gentoo /var/db/repos/gentoo
 COPY --from=kernel /boot /boot
 COPY --from=kernel /lib/modules /lib/modules
+COPY --from=efistub /usr/lib/systemd/boot/efi /usr/lib/systemd/boot/efi
 
 MAINTAINER https://github.com/dracutdevs/dracut
 
index 5dc610379e56d7a597afda2546ed2594d25b9986..0d1bd6806b7e5e26bfa2d28328bd54cf8c7e8304 100755 (executable)
@@ -40,4 +40,9 @@ if ! [ -f "$VMLINUZ" ]; then
     fi
 fi
 
-exec "$BIN" "${ARGS[@]}" -kernel "$VMLINUZ" "$@"
+# only set -kernel if -initrd is specified
+if [[ $* == *-initrd* ]]; then
+    ARGS+=(-kernel "$VMLINUZ")
+fi
+
+exec "$BIN" "${ARGS[@]}" "$@"