diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-03 13:54:25 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-03 13:54:25 +0000 |
commit | 9cb1c4df7b9ce1a9ad1312621b0f2b16a94fba3a (patch) | |
tree | 2efb72864cc69e174c9c5ee33efb88a5f1553b48 /test/run-qemu | |
parent | Initial commit. (diff) | |
download | dracut-9cb1c4df7b9ce1a9ad1312621b0f2b16a94fba3a.tar.xz dracut-9cb1c4df7b9ce1a9ad1312621b0f2b16a94fba3a.zip |
Adding upstream version 060+5.upstream/060+5
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/run-qemu')
-rwxr-xr-x | test/run-qemu | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/test/run-qemu b/test/run-qemu new file mode 100755 index 0000000..41d458a --- /dev/null +++ b/test/run-qemu @@ -0,0 +1,74 @@ +#!/bin/bash +# Check which virtualization technology to use +# We prefer kvm, kqemu, userspace in that order. + +export PATH=/usr/sbin:/usr/bin:/sbin:/bin +ARCH="${ARCH-$(uname -m)}" +QEMU_CPU="${QEMU_CPU:-max}" + +[[ -x /usr/bin/qemu ]] && BIN=/usr/bin/qemu && ARGS=(-cpu "$QEMU_CPU") +(lsmod | grep -q '^kqemu ') && BIN=/usr/bin/qemu && ARGS=(-kernel-kqemu -cpu host) +[[ -z ${NO_KVM-} && -c /dev/kvm && -x /usr/bin/kvm ]] && BIN=/usr/bin/kvm && ARGS=(-cpu host) +[[ -z ${NO_KVM-} && -c /dev/kvm && -x /usr/bin/qemu-kvm ]] && BIN=/usr/bin/qemu-kvm && ARGS=(-cpu host) +[[ -z ${NO_KVM-} && -c /dev/kvm && -x /usr/libexec/qemu-kvm ]] && BIN=/usr/libexec/qemu-kvm && ARGS=(-cpu host) +[[ -x "/usr/bin/qemu-system-${ARCH}" ]] && BIN="/usr/bin/qemu-system-${ARCH}" && ARGS=(-cpu "$QEMU_CPU") +[[ -z ${NO_KVM-} && -c /dev/kvm && -x "/usr/bin/qemu-system-${ARCH}" ]] && BIN="/usr/bin/qemu-system-${ARCH}" && ARGS=(-enable-kvm -cpu host) + +[[ $BIN ]] || { + echo "Could not find a working KVM or QEMU to test with!" >&2 + echo "Please install kvm or qemu." >&2 + exit 1 +} + +case "$ARCH" in + aarch64 | arm64) + ARGS+=(-M "virt,gic-version=max") + ;; + amd64 | i?86 | x86_64) + ARGS+=(-M q35) + ;; + arm | armhf | armv7l) + ARGS+=(-M virt) + ;; + ppc64el | ppc64le) + ARGS+=(-M "cap-ccf-assist=off,cap-cfpc=broken,cap-ibs=broken,cap-sbbc=broken") + ;; +esac + +# Provide rng device sourcing the hosts /dev/urandom and other standard parameters +ARGS+=(-smp 2 -m 1024 -nodefaults -vga none -display none -no-reboot -device virtio-rng-pci) + +if ! [[ $* == *-daemonize* ]] && ! [[ $* == *-daemonize* ]]; then + ARGS+=(-serial stdio) +fi + +KVERSION=${KVERSION-$(uname -r)} + +VMLINUZ="/lib/modules/${KVERSION}/vmlinuz" +if ! [ -f "$VMLINUZ" ]; then + VMLINUZ="/lib/modules/${KVERSION}/vmlinux" +fi + +if ! [ -f "$VMLINUZ" ]; then + [[ -f /etc/machine-id ]] && read -r MACHINE_ID < /etc/machine-id + + if [[ $MACHINE_ID ]] && { [[ -d /boot/${MACHINE_ID} ]] || [[ -L /boot/${MACHINE_ID} ]]; }; then + VMLINUZ="/boot/${MACHINE_ID}/$KVERSION/linux" + elif [ -f "/boot/vmlinuz-${KVERSION}" ]; then + VMLINUZ="/boot/vmlinuz-${KVERSION}" + elif [ -f "/boot/vmlinux-${KVERSION}" ]; then + VMLINUZ="/boot/vmlinux-${KVERSION}" + else + echo "Could not find a Linux kernel version $KVERSION to test with!" >&2 + echo "Please install linux." >&2 + exit 1 + fi +fi + +# only set -kernel if -initrd is specified +if [[ $* == *-initrd* ]]; then + ARGS+=(-kernel "$VMLINUZ") +fi + +echo "${0##*/}: $BIN ${ARGS[*]@Q} ${*@Q}" +exec "$BIN" "${ARGS[@]}" "$@" |