]> git.ipfire.org Git - thirdparty/dracut-ng.git/commitdiff
test: fix Linux kernel detection for qemu runs
authorJo Zzsi <jozzsicsataban@gmail.com>
Sat, 2 Aug 2025 11:38:09 +0000 (07:38 -0400)
committerLaszlo <laszlo.gombos@gmail.com>
Sat, 9 Aug 2025 11:02:16 +0000 (07:02 -0400)
Determine KVERSION from the generated initramfs for qemu runs.

Extend fallback detection even when KVERSION is specified.

test/run-qemu

index 974f1db1a295e27c42ffaf53607c9d0e1d1ec5cf..0250a8a8769767871f15016cbf868384c8a58ece 100755 (executable)
@@ -29,11 +29,11 @@ set_vmlinux_env() {
                 VMLINUZ="/boot/Image-${KVERSION}"
             fi
         fi
-    else
-        VMLINUZ=$(find /boot/vmlinuz-* -type f 2> /dev/null | tail -1)
-        ! [ -f "$VMLINUZ" ] && VMLINUZ=$(find /lib/modules/ -type f -name vmlinuz 2> /dev/null | tail -1)
     fi
 
+    ! [ -f "${VMLINUZ-}" ] && VMLINUZ=$(find /boot/vmlinuz-* -type f 2> /dev/null | tail -1)
+    ! [ -f "${VMLINUZ-}" ] && VMLINUZ=$(find /lib/modules/ -type f -name vmlinuz 2> /dev/null | tail -1)
+
     if ! [ -f "$VMLINUZ" ]; then
         echo "Could not find a Linux kernel version to test with!" >&2
         echo "Please install linux." >&2
@@ -90,6 +90,11 @@ fi
 
 # only set -kernel if -initrd is specified
 if [[ $* == *-initrd* ]]; then
+    for arg in "$@"; do
+        [[ $1 == *-initrd* ]] && break
+    done
+
+    KVERSION=$(lsinitrd "$arg" | grep modules.dep | head -1 | rev | cut -d'/' -f2 | rev)
     set_vmlinux_env
     ARGS+=(-kernel "$VMLINUZ")
 fi