1
0
Fork 0

experiment with vm stuff

This commit is contained in:
Massaki Archambault 2018-10-11 20:25:32 -04:00
parent a74151075e
commit bc81036d85
3 changed files with 129 additions and 20 deletions

View File

@ -44,28 +44,32 @@ __nmap_iface() {
} }
# start looking-glass # start looking-glass
game() { play-vm() {
echo "Stopping services" if ! [ -S /tmp/win10.sock ]; then
sudo systemctl stop cronie echo "Cannot find spice socket! Is the vm started?"
systemctl --user stop redshift compton wallpaper else
echo "Stopping services"
sudo systemctl stop cronie
systemctl --user stop redshift compton wallpaper
echo "Setup cpuset cgroup for host" echo "Setup cpuset cgroup for host"
sudo cset set -c 0,4 -s system sudo cset set -c 0,4 -s system
sudo cset proc -m -f root -t system sudo cset proc -m -f root -t system
sudo cset proc -k -f root -t system --force sudo cset proc -k -f root -t system --force
echo "Setup cpumask" echo "Setup cpumask"
sudo bash -c "echo 5 > /sys/devices/virtual/workqueue/cpumask" sudo bash -c "echo 5 > /sys/devices/virtual/workqueue/cpumask"
echo "Starting looking-glass" echo "Starting looking-glass"
LD_PRELOAD=/usr/\$LIB/libgamemodeauto.so looking-glass-client -o opengl:preventBuffer=0 -MFk LD_PRELOAD=/usr/\$LIB/libgamemodeauto.so looking-glass-client -p 0 -c /tmp/win10.sock -o opengl:preventBuffer=0 -MF
echo "Restore system" echo "Restore system"
# cpumask # cpumask
sudo bash -c "echo f > /sys/devices/virtual/workqueue/cpumask" sudo bash -c "echo f > /sys/devices/virtual/workqueue/cpumask"
# cpuset # cpuset
sudo cset set -d system &>/dev/null sudo cset set -d system &>/dev/null
# services # services
systemctl --user start redshift compton wallpaper systemctl --user start redshift compton wallpaper
sudo systemctl start cronie sudo systemctl start cronie
fi
} }

36
files/.local/bin/mount-ramdisk Executable file
View File

@ -0,0 +1,36 @@
#!/bin/bash
#mount_dir="$(mktemp -d /tmp/ramdisk.XXXX)"
mount_dir="/tmp/ramdisk"
mkdir "$mount_dir"
img_file="$mount_dir/img"
if [[ ! -f "$1" ]]; then
echo "'$1' is an invalid file"
exit 1
fi
# create tmpfs and copy the file on it
img_size="$(stat --printf="%s" "$1")"
sudo mount -t tmpfs size=$img_size,noexec,nosid,uid=$UID,gid=$GID "$mount_dir"
cp "$1" "$img_file"
read -p "press enter to unmount"
# check if the file is in use
while lsof "$mount_dir" | grep -q "$mount_dir"; do
echo "Device is busy"
read -p "press enter to unmount"
done
# save the image to disk
if cp "$img_file" "$1.tmp"; then
mv "$1.tmp" "$1"
else
echo "Error copying '$img_file' back to disk!"
exit 1
fi
# cleanup
sudo umount "$mount_dir"
rmdir "$mount_dir"

69
files/.local/bin/run-vm Executable file
View File

@ -0,0 +1,69 @@
#!/bin/bash
export QEMU_AUDIO_DRV=pa
export QEMU_PA_SAMPLE=1024
export QEMU_AUDIO_TIMER_PERIOD=150
export QEMU_PA_SERVER=/run/user/1000/pulse/native
# defrag ram
sudo sh -c "echo 1 > /proc/sys/vm/compact_memory"
# assign hugepages
sudo sysctl -w vm.nr_hugepages=8192
# start qemu
qemu-system-x86_64 -name win10 -S \
-machine q35,accel=kvm -device intel-iommu \
-cpu host,hv_time,hv_relaxed,hv_vapic,hv_spinlocks=0x1fff,hv_vendor_id=0xDEADBEEFFF,kvm=off \
-smp 6,sockets=1,cores=3,threads=2 \
-m 16G -mem-prealloc -mem-path /dev/hugepages/libvirt/qemu/win10 \
-drive file=/usr/share/ovmf/x64/OVMF_CODE.fd,if=pflash,format=raw,unit=0,readonly=on \
-realtime mlock=off \
-uuid 9d7df055-d6d1-4551-bb25-ef2ddb835c4d \
-no-user-config \
-rtc base=localtime,driftfix=slew \
-global kvm-pit.lost_tick_policy=delay \
-no-hpet -no-shutdown \
-global ICH9-LPC.disable_s3=1 \
-global ICH9-LPC.disable_s4=1 \
-boot strict=on \
-device i82801b11-bridge,id=pci.1,bus=pcie.0,addr=0x1e \
-device pci-bridge,chassis_nr=2,id=pci.2,bus=pci.1,addr=0x0 \
-device pcie-root-port,port=0x10,chassis=3,id=pci.3,bus=pcie.0,multifunction=on,addr=0x2 \
-device pcie-root-port,port=0x11,chassis=4,id=pci.4,bus=pcie.0,addr=0x2.0x1 \
-device pcie-root-port,port=0x12,chassis=5,id=pci.5,bus=pcie.0,addr=0x2.0x2 \
-device pcie-root-port,port=0x13,chassis=6,id=pci.6,bus=pcie.0,addr=0x2.0x3 \
-device pcie-root-port,port=0x14,chassis=7,id=pci.7,bus=pcie.0,addr=0x2.0x4 \
-device pcie-root-port,port=0x15,chassis=8,id=pci.8,bus=pcie.0,addr=0x2.0x5 \
-device ich9-usb-ehci1,id=usb,bus=pcie.0,addr=0x1d.0x7 \
-device ich9-usb-uhci1,masterbus=usb.0,firstport=0,bus=pcie.0,multifunction=on,addr=0x1d \
-device ich9-usb-uhci2,masterbus=usb.0,firstport=2,bus=pcie.0,addr=0x1d.0x1 \
-device ich9-usb-uhci3,masterbus=usb.0,firstport=4,bus=pcie.0,addr=0x1d.0x2 \
-device virtio-scsi-pci,id=scsi0,num_queues=6,bus=pci.5,addr=0x0 \
-device virtio-serial-pci,id=virtio-serial0,bus=pci.3,addr=0x0 \
-device scsi-hd,bus=scsi0.0,channel=0,scsi-id=0,lun=0,drive=drive-scsi0-0-0-0,id=scsi0-0-0-0,bootindex=1 \
-drive file=$HOME/Documents/virtualmachines/img/win10.img,format=raw,if=none,id=drive-scsi0-0-0-0 \
-drive file=/dev/disk/by-label/DATA,format=raw,if=none,id=drive-scsi0-0-0-3,cache=none,aio=native \
-device scsi-hd,bus=scsi0.0,channel=0,scsi-id=0,lun=3,drive=drive-scsi0-0-0-3,id=scsi0-0-0-3,write-cache=on \
-drive if=none,id=drive-sata0-0-1,media=cdrom,readonly=on \
-device ide-cd,bus=ide.1,drive=drive-sata0-0-1,id=sata0-0-1 \
-chardev spicevmc,id=charchannel0,name=vdagent \
-device virtserialport,bus=virtio-serial0.0,nr=1,chardev=charchannel0,id=channel0,name=com.redhat.spice.0 \
-spice unix,addr=/tmp/win10.sock,disable-ticketing,image-compression=off,seamless-migration=on \
-device qxl-vga,id=video0,ram_size=67108864,vram_size=67108864,vram64_size_mb=0,vgamem_mb=16,max_outputs=1,bus=pcie.0,addr=0x1 \
-device intel-hda,id=sound0,bus=pci.2,addr=0x2 \
-device hda-duplex,id=sound0-codec0,bus=sound0.0,cad=0 \
-chardev spicevmc,id=charredir0,name=usbredir \
-device usb-redir,chardev=charredir0,id=redir0,bus=usb.0,port=2 \
-device usb-host,hostbus=1,hostaddr=3,id=hostdev0,bus=usb.0,port=1 \
-device vfio-pci,host=01:00.0,id=hostdev1,bus=pci.6,addr=0x0 \
-device vfio-pci,host=00:1f.6,id=hostdev2,bus=pci.2,addr=0x3 \
-device usb-host,hostbus=1,hostaddr=11,id=hostdev3,bus=usb.0,port=3 \
-device virtio-balloon-pci,id=balloon0,bus=pci.7,addr=0x0 \
-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \
-object memory-backend-file,id=shmmem-shmem0,mem-path=/dev/shm/looking-glass,size=33554432,share=yes \
-device ivshmem-plain,id=shmem0,memdev=shmmem-shmem0,bus=pci.2,addr=0x4 \
-msg timestamp=on
# free hugepages
sudo sysctl -w vm.nr_hugepages=0