]> git.ipfire.org Git - thirdparty/dracut.git/blob - test/run-qemu
test: log qemu calls to ease debugging
[thirdparty/dracut.git] / test / run-qemu
1 #!/bin/bash
2 # Check which virtualization technology to use
3 # We prefer kvm, kqemu, userspace in that order.
4
5 export PATH=/usr/sbin:/usr/bin:/sbin:/bin
6 ARCH="${ARCH-$(uname -m)}"
7 QEMU_CPU="${QEMU_CPU:-max}"
8
9 [[ -x /usr/bin/qemu ]] && BIN=/usr/bin/qemu && ARGS=(-cpu "$QEMU_CPU")
10 (lsmod | grep -q '^kqemu ') && BIN=/usr/bin/qemu && ARGS=(-kernel-kqemu -cpu host)
11 [[ -c /dev/kvm && -x /usr/bin/kvm ]] && BIN=/usr/bin/kvm && ARGS=(-cpu host)
12 [[ -c /dev/kvm && -x /usr/bin/qemu-kvm ]] && BIN=/usr/bin/qemu-kvm && ARGS=(-cpu host)
13 [[ -c /dev/kvm && -x /usr/libexec/qemu-kvm ]] && BIN=/usr/libexec/qemu-kvm && ARGS=(-cpu host)
14 [[ -x "/usr/bin/qemu-system-${ARCH}" ]] && BIN="/usr/bin/qemu-system-${ARCH}" && ARGS=(-cpu "$QEMU_CPU")
15 [[ -c /dev/kvm && -x "/usr/bin/qemu-system-${ARCH}" ]] && BIN="/usr/bin/qemu-system-${ARCH}" && ARGS=(-enable-kvm -cpu host)
16
17 [[ $BIN ]] || {
18 echo "Could not find a working KVM or QEMU to test with!" >&2
19 echo "Please install kvm or qemu." >&2
20 exit 1
21 }
22
23 # Provide rng device sourcing the hosts /dev/urandom and other standard parameters
24 ARGS+=(-M q35 -smp 2 -m 1024 -nodefaults -vga none -display none -no-reboot -device virtio-rng-pci)
25
26 if ! [[ $* == *-daemonize* ]] && ! [[ $* == *-daemonize* ]]; then
27 ARGS+=(-serial stdio)
28 fi
29
30 KVERSION=${KVERSION-$(uname -r)}
31
32 VMLINUZ="/lib/modules/${KVERSION}/vmlinuz"
33
34 if ! [ -f "$VMLINUZ" ]; then
35 [[ -f /etc/machine-id ]] && read -r MACHINE_ID < /etc/machine-id
36
37 if [[ $MACHINE_ID ]] && { [[ -d /boot/${MACHINE_ID} ]] || [[ -L /boot/${MACHINE_ID} ]]; }; then
38 VMLINUZ="/boot/${MACHINE_ID}/$KVERSION/linux"
39 else
40 VMLINUZ="/boot/vmlinuz-${KVERSION}"
41 fi
42 fi
43
44 # only set -kernel if -initrd is specified
45 if [[ $* == *-initrd* ]]; then
46 ARGS+=(-kernel "$VMLINUZ")
47 fi
48
49 echo "${0##*/}: $BIN ${ARGS[*]@Q} ${*@Q}"
50 exec "$BIN" "${ARGS[@]}" "$@"