-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·116 lines (99 loc) · 3.3 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/zsh
name="Windows"
dir=/home/notneo/BillyGates
# check permissions
if [[ "$UID" != "0" ]]; then
echo "$0: Root permissions are needed to run $name virtual machine" 2>/dev/null
exit 1
fi
# virtual raid config
if [[ "$1" == "stop" ]]; then
# stop virtual RAID disk
mdadm --stop --scan
losetup --detach-all
echo "$0: The virtual RAID was shutdown" &
exit 0
else
# setup virtual RAID disk
losetup -f `dirname "$0"`/efi1
losetup -f `dirname "$0"`/efi2
mdadm --build --verbose /dev/md0 --chunk=512 --level=linear --raid-devices=3 /dev/loop0 /dev/nvme1n1p2 /dev/loop1
sleep 1
chown $USER /dev/md0
# check if a passthrough vm is running
if ps -ef | grep qemu-system-x86_64 | grep -q multifunction=on; then
echo "$0: A GPU passthrough virtual machine is already running!" &
exit 1
else
cp /usr/share/edk2-ovmf/x64/OVMF_VARS.fd /tmp/vars.fd
echo "$0: Starting $name virtual machine"
local -a qemu_params=(
-name $name,process=$name \
-machine type=pc,accel=kvm \
-enable-kvm \
-m 16G \
-smp sockets=1,cores=2,threads=2 \
-cpu host,kvm=off,hv_time,hv_relaxed,hv_vapic,hv_spinlocks=0x1fff \
-nodefaults \
-drive if=pflash,format=raw,readonly=on,file=/usr/share/edk2-ovmf/x64/OVMF_CODE.fd \
-drive if=pflash,format=raw,file=/tmp/vars.fd \
)
local -a qemu_rtc_params=(
-rtc clock=host,base=localtime \
)
local -a qemu_source_params=(
-drive id=system,file=/dev/md0,media=disk,format=raw,cache=none \
-drive id=files,file=/dev/sda,media=disk,format=raw,cache=none \
-boot order=c \
)
local -a qemu_pass_video=(
# IVShMem
-device ivshmem-plain,memdev=ivshmem \
-object memory-backend-file,id=ivshmem,share=on,mem-path=/dev/shm/looking-glass,size=32M \
# GPU Passthrough
-vga none \
-nographic \
-serial none \
-parallel none \
-device vfio-pci,host=01:00.0,multifunction=on \
)
local -a qemu_pass_input=(
# Looking Glass input
-spice port=5901,addr=127.0.0.1,disable-ticketing=on \
# Clipboard
-device virtio-serial-pci \
-chardev spicevmc,id=vdagent,name=vdagent \
-device virtserialport,chardev=vdagent,name=com.redhat.spice.0 \
)
local -a qemu_usb_host=(
-usb \
# Keyboard
-usbdevice keyboard \
# Mouse
-usbdevice mouse \
# MIDI Keyboard
-device usb-host,vendorid=0x2467,productid=0x2018 \
# Physical mouse/keyboard
#-device usb-host,vendorid=0x046d,productid=0xc52b\
#-device usb-host,vendorid=0x046d,productid=0xc083\
)
local -a qemu_emulated_sound=(
# Scream
-device ivshmem-plain,memdev=scream-ivshmem \
-object memory-backend-file,id=scream-ivshmem,share=on,mem-path=/dev/shm/scream-ivshmem,size=2M \
)
local -a qemu_network=(
-nic user,model=virtio-net-pci\
)
qemu-system-x86_64 "${qemu_params[@]}" \
"${qemu_rtc_params[@]}" \
"${qemu_emulated_sound[@]}" \
"${qemu_source_params[@]}" \
"${qemu_pass_video[@]}" \
"${qemu_pass_input[@]}" \
"${qemu_network[@]}" \
"${qemu_usb_host[@]}"
echo "$0: $name virtual machine was shutdown"
exit 0
fi
fi