Last active
October 12, 2020 10:22
-
-
Save xomachine/eb9577a8be7972a1fe85c43bef1eb2e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
CURPATH=$(realpath $(dirname $0)) | |
if [ x"$DISPLAY" = x ]; then | |
SUDO=sudo | |
else | |
SUDO=lxsudo | |
fi | |
CPUS="0,1,2" | |
startvm(){ | |
OPTIONS="" | |
OPTIONS+=" -enable-kvm " | |
OPTIONS+=" -name guest=win10,debug-threads=off " | |
OPTIONS+=" -machine pc-i440fx-3.0,accel=kvm,usb=off,vmport=off,dump-guest-core=off " | |
OPTIONS+=" -cpu host,kvm=off " | |
OPTIONS+=" -device virtio-serial " | |
#OPTIONS+=" -chardev spicevmc,id=vdagent,name=vdagent " | |
#OPTIONS+=" -device virtserialport,chardev=vdagent,name=com.redhat.spice.0 " | |
#OPTIONS+=" -spice unix,gl=on,addr=/tmp/.X11-unix/windows.sock,disable-ticketing,seamless-migration " | |
OPTIONS+=" -vga none " | |
#OPTIONS+=" -vga qxl " | |
# Keyboard and mouse passthrough | |
#OPTIONS+=" -device usb-host,vendorid=0x09da,productid=0x9090 " # Mouse | |
OPTIONS+=" -device usb-host,vendorid=0x12d1,productid=0x1506 " # Modem | |
OPTIONS+=" -device usb-host,vendorid=0x0e18,productid=0x0001 " # RD | |
OPTIONS+=" -device usb-tablet " | |
OPTIONS+=" -device usb-kbd " | |
#OPTIONS+=" -device virtio-mouse-pci " | |
#OPTIONS+=" -device virtio-input-host-pci,evdev=/dev/input/by-id/usb-A4TECH_USB_Device-if01-event-mouse " | |
OPTIONS+=" -object input-linux,id=kbd,evdev=/dev/input/by-id/usb-Logitech_Logitech_USB_Keyboard-event-kbd,grab_all=on,repeat=on " | |
OPTIONS+=" -object input-linux,id=mouseev,evdev=/dev/input/by-id/usb-A4TECH_USB_Device-if01-event-mouse " | |
OPTIONS+=" -object input-linux,id=mousekbd,evdev=/dev/input/by-id/usb-A4TECH_USB_Device-event-kbd " | |
#OPTIONS+=" -object input-linux,id=joystick,evdev=/dev/input/by-id/usb-Logitech_Logitech_USB_Keyboard-if01-event-joystick " | |
#OPTIONS+=" -vga cirrus " | |
OPTIONS+=" -drive file=/usr/share/ovmf/x64/OVMF_CODE.fd,if=pflash,format=raw,unit=0,readonly=on " | |
OPTIONS+=" -drive file=$CURPATH/nvram_VARS.fd,if=pflash,format=raw,unit=1 " | |
OPTIONS+=" -m 8192 " | |
#OPTIONS+=" -m 3608 " | |
#OPTIONS+=" -baloon virtio " | |
OPTIONS+=" -smp 3,sockets=1,cores=3,threads=1 " | |
OPTIONS+=" -device virtio-scsi-pci,id=scsi " | |
#OPTIONS+=" -device ahci,id=ahci-controller " | |
OPTIONS+=" -drive file=$CURPATH/DriveC.img,format=qcow2,if=none,id=disk " | |
OPTIONS+=" -drive file=$CURPATH/games.img,format=qcow2,if=none,id=games " | |
#OPTIONS+=" -drive file=$CURPATH/sdb_overlay.qcow2,format=qcow2,if=none,id=wingames " | |
OPTIONS+=" -device scsi-hd,drive=disk " | |
OPTIONS+=" -device scsi-hd,drive=games " | |
#OPTIONS+=" -device scsi-hd,drive=wingames " | |
#OPTIONS+=" -drive file=/dev/sdb2,format=raw,if=none,id=shareddisk " | |
#OPTIONS+=" -drive file=fat:rw:/storage,id=storage " | |
#OPTIONS+=" -device ide-hd,drive=storage " | |
#OPTIONS+=" -drive file=fat:rw:/wingames,id=wingames " | |
#OPTIONS+=" -device ide-hd,drive=wingames " | |
OPTIONS+=" -cdrom /home/xomachine/.Soft/iso/virtio-win-0.1.135.iso " | |
OPTIONS+=" -device vfio-pci,host=01:00.0,id=hostdev0,bus=pci.0 " | |
OPTIONS+=" -device vfio-pci,host=01:00.1,id=hostdev1,bus=pci.0 " | |
OPTIONS+=" -usb " | |
#OPTIONS+=" -net nic,vlan=0,model=virtio,id=net0" | |
OPTIONS+=" -netdev user,id=net0,net=10.0.2.0/24,dhcpstart=10.0.2.10,hostfwd=tcp::15900-:5900,hostfwd=tcp::13389-:3389,smb=$PWD/shared,smbserver=10.0.2.4 " | |
#OPTIONS+=" -netdev user,smb=$PWD/shared,smbserver=10.0.2.4,id=net1 " | |
#OPTIONS+=" -netdev user,smb=/storage,smbserver=10.0.2.4,id=net0 " | |
#OPTIONS+=" -device virtio-net-pci,netdev=net1 " | |
OPTIONS+=" -device virtio-net-pci,netdev=net0 " | |
#OPTIONS+=" -device hda-micro " | |
OPTIONS+=" -soundhw hda " | |
#OPTIONS+=" -soundhw ac97 " | |
OPTIONS+=" -boot strict=on " | |
#export QEMU_AUDIO_DRV="alsa" | |
export QEMU_AUDIO_DRV="pa" | |
#export QEMU_PA_SAMPLES=2048 | |
export QEMU_PA_SERVER="/run/user/1000/pulse/native" | |
export QEMU_PA_SOURCE="alsa_input.pci-0000_00_1f.3.analog-stereo" | |
ulimit -l unlimited | |
echo "got ready signal! starting" >> $CURPATH/last.log | |
/usr/sbin/qemu-system-x86_64 $OPTIONS >> "$CURPATH/last.log" 2>&1 | |
echo "finishing vm" >> $CURPATH/last.log | |
} | |
rootpart() { | |
echo "chmod devs" | |
chmod -R 777 /dev/vfio/* | |
chmod -R 777 /dev/bus/usb/* | |
echo "mounting dirs" | |
mount --bind /storage $CURPATH/shared/storage | |
mount --bind /wingames $CURPATH/shared/wingames | |
echo "Preparing cpu affinity" | |
cset shield -c "$CPUS" -k on -v | |
cset shield -s -p $1 -v | |
echo "sending ready signal" | |
kill -10 $1 | |
ulimit -l unlimited | |
echo "sleeping..." | |
while kill -0 $1 2>/dev/null; do | |
sleep 1 | |
done | |
echo "wakeup! unmount everything" | |
cset shield -r -v | |
umount $CURPATH/shared/storage | |
umount $CURPATH/shared/wingames | |
} | |
if [ $UID = 0 ]; then | |
if [ -z "$1" ]; then echo "Run script as user!"; exit 1; fi | |
rootpart $1 | |
else | |
echo > $CURPATH/last.log | |
trap startvm 10 | |
$SUDO sh $0 $$ &> "$CURPATH/lastroot.log" & | |
sleep 1 | |
wait %1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment