-
Notifications
You must be signed in to change notification settings - Fork 1
/
run.sh
executable file
·57 lines (50 loc) · 1.59 KB
/
run.sh
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
set -eo pipefail
KERNEL='kernel/kernel'
INITRD='initrd'
CMDLINE=()
NUM_CPUS=1
case "$1" in
shell) # Serial console
QEMU_DISPLAY_ARGS=(-display none -vga none)
CMDLINE+=(console=ttyS0)
;;
text) # Text console
QEMU_DISPLAY_ARGS=(-display "sdl,gl=off" -vga cirrus)
CMDLINE+=(console=tty1)
;;
*) # Framebuffer console
QEMU_DISPLAY_ARGS=(-display "sdl,gl=off,show-cursor=off")
CMDLINE+=(console=tty1)
;;
esac
QEMU_BINARY_PREFIX=''
QEMU_BINARY_SUFFIX=''
QEMU_VIRT_TECH_ARGS=()
if [ -r /dev/kvm ] && [ -w /dev/kvm ] &&
command -v kvm-ok >/dev/null && kvm-ok &>/dev/null; then
QEMU_VIRT_TECH_ARGS=(-enable-kvm)
fi
if command -v wslpath >/dev/null; then
PATH=${PATH}:/mnt/c/Windows/System32
QEMU_INSTALL_DIR=$(reg.exe query 'HKLM\Software\QEMU' /v Install_Dir /t REG_SZ | grep '^ Install_Dir' | sed 's/ / /g' | cut -f4- -d' ')
QEMU_BINARY_PREFIX="$(wslpath -- "${QEMU_INSTALL_DIR}" | tr -d '\r\n')/"
QEMU_BINARY_SUFFIX='.exe'
QEMU_VIRT_TECH_ARGS=(-accel "whpx,kernel-irqchip=off" -accel tcg)
KERNEL=$(wslpath -w "${KERNEL}")
INITRD=$(wslpath -w "${INITRD}")
fi
QEMU_BIN="${QEMU_BINARY_PREFIX}qemu-system-i386${QEMU_BINARY_SUFFIX}"
"${QEMU_BIN}" \
-kernel "${KERNEL}" \
-initrd "${INITRD}" \
-append "${CMDLINE[*]}" \
-d guest_errors \
"${QEMU_DISPLAY_ARGS[@]}" \
-device ac97 \
-chardev stdio,mux=on,id=char0 \
-serial chardev:char0 \
-mon char0,mode=readline \
-m 512M \
-smp "sockets=1,cores=${NUM_CPUS},threads=1" \
"${QEMU_VIRT_TECH_ARGS[@]}"