summaryrefslogtreecommitdiff
path: root/test/run-qemu
blob: 00c2f6a85eca52c206721ec11441fe3c13928f2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/bin/bash
# Check which virtualization technology to use
# We prefer kvm, kqemu, userspace in that order.
export PATH=/sbin:/bin:/usr/sbin:/usr/bin

[[ -x /usr/bin/qemu ]] && BIN=/usr/bin/qemu && ARGS=""
$(lsmod | grep -q '^kqemu ') && BIN=/usr/bin/qemu && ARGS="-kernel-kqemu "
[[ -c /dev/kvm && -x /usr/bin/kvm ]] && BIN=/usr/bin/kvm && ARGS=""
[[ -c /dev/kvm && -x /usr/bin/qemu-kvm ]] && BIN=/usr/bin/qemu-kvm && ARGS=""
[[ -c /dev/kvm && -x /usr/libexec/qemu-kvm ]] && BIN=/usr/libexec/qemu-kvm && ARGS=""

[[ $BIN ]] || {
   echo "Could not find a working KVM or QEMU to test with!" >&2
   echo "Please install kvm or qemu." >&2
   exit 1
}

KVERSION=${KVERSION-$(uname -r)}

[[ -f /etc/machine-id ]] && read MACHINE_ID < /etc/machine-id

if [[ $MACHINE_ID ]] && ( [[ -d /boot/${MACHINE_ID} ]] || [[ -L /boot/${MACHINE_ID} ]] ); then
    VMLINUZ="/boot/${MACHINE_ID}/$KVERSION/linux"
else
    VMLINUZ="/boot/vmlinuz-${KVERSION}"
fi

exec sudo $BIN $ARGS -kernel $VMLINUZ "$@"