forked from dracutdevs/dracut
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-qemu
executable file
·42 lines (32 loc) · 1.61 KB
/
run-qemu
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash
# Check which virtualization technology to use
# We prefer kvm, kqemu, userspace in that order.
export PATH=/usr/sbin:/usr/bin:/sbin:/bin
[[ -x /usr/bin/qemu ]] && BIN=/usr/bin/qemu && ARGS=(-cpu max)
(lsmod | grep -q '^kqemu ') && BIN=/usr/bin/qemu && ARGS=(-kernel-kqemu -cpu host)
[[ -c /dev/kvm && -x /usr/bin/kvm ]] && BIN=/usr/bin/kvm && ARGS=(-cpu host)
[[ -c /dev/kvm && -x /usr/bin/qemu-kvm ]] && BIN=/usr/bin/qemu-kvm && ARGS=(-cpu host)
[[ -c /dev/kvm && -x /usr/libexec/qemu-kvm ]] && BIN=/usr/libexec/qemu-kvm && ARGS=(-cpu host)
[[ -x /usr/bin/qemu-system-$(uname -m) ]] && BIN=/usr/bin/qemu-system-$(uname -m) && ARGS=(-cpu max)
[[ -c /dev/kvm && -x /usr/bin/qemu-system-$(uname -m) ]] && BIN=/usr/bin/qemu-system-$(uname -m) && 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
}
# Provide rng device sourcing the hosts /dev/urandom and other standard parameters
ARGS+=(-M q35 -smp 2 -m 512 -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
[[ -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"
else
VMLINUZ="/boot/vmlinuz-${KVERSION}"
fi
fi
exec "$BIN" "${ARGS[@]}" -kernel "$VMLINUZ" "$@"