Skip to content

Instantly share code, notes, and snippets.

@fredmajor
Created November 26, 2017 22:35
Show Gist options
  • Save fredmajor/ff87acecd59fdcac19249957e106b4bf to your computer and use it in GitHub Desktop.
Save fredmajor/ff87acecd59fdcac19249957e106b4bf to your computer and use it in GitHub Desktop.
#!/bin/bash
# This starts a highly tuned Windows 10 VM with GPU-passthrough, Q35 chipset, ethernet bridging, PCI passthrough for the USB controller, hugepages, etc.
# QEMU name and PID
OPTS="-name windows-10-home"
OPTS="$OPTS -pidfile /tmp/windows-10-pro.pid"
# Processor core2duo qemu64 host
# OPTS="$OPTS -cpu qemu64,kvm=off,hv_vendor_id=123456789asx"
OPTS="$OPTS -cpu host,kvm=off,hv_vendor_id=123456789ab,hv_time,hv_relaxed,hv_vapic,hv_spinlocks=0x1fff"
OPTS="$OPTS -smp 6,sockets=1,cores=3,threads=2"
OPTS="$OPTS -vcpu vcpunum=0,affinity=1 -vcpu vcpunum=1,affinity=5"
OPTS="$OPTS -vcpu vcpunum=2,affinity=2 -vcpu vcpunum=3,affinity=6"
OPTS="$OPTS -vcpu vcpunum=4,affinity=3 -vcpu vcpunum=5,affinity=7"
OPTS="$OPTS -enable-kvm"
# Machine
# OPTS="$OPTS -machine type=pc-i440fx-2.1,accel=kvm"
# OPTS="$OPTS -machine type=q35,accel=kvm"
OPTS="$OPTS -machine type=q35"
# The following setting enables S3 (suspend to RAM). OVMF supports S3
# suspend/resume. Disable when using Q35
#OPTS="$OPTS -global PIIX4_PM.disable_s3=0"
# Memory
OPTS="$OPTS -m 16G"
OPTS="$OPTS -mem-path /dev/hugepages"
OPTS="$OPTS -mem-prealloc"
OPTS="$OPTS -balloon none"
# Hardware clock
OPTS="$OPTS -rtc clock=host,base=utc"
# Sound hardware
#QEMU_PA_SAMPLES=128
#export QEMU_AUDIO_DRV=pa
#OPTS="$OPTS -soundhw hda"
# Graphic card passthrough (Gigabyte GeForce GTX 980 G1 Gaming)
OPTS="$OPTS -device vfio-pci,host=01:00.0,multifunction=on"
OPTS="$OPTS -device vfio-pci,host=01:00.1"
# USB HUB passthrough, must be accompanied by virsh nodeded-attach/reattach around the actual invocation
OPTS="$OPTS -device i82801b11-bridge,id=pci.1,bus=pcie.0,addr=0x1e"
OPTS="$OPTS -device pci-bridge,chassis_nr=2,id=pci.2,bus=pci.1,addr=0x0"
OPTS="$OPTS -device vfio-pci,host=00:14.0,id=hostdev0,bus=pci.2,addr=0x3"
# USB 1.0 passtrhough
#OPTS="$OPTS -usb"
#OPTS="$OPTS -device usb-host,bus=usb-bus.0,vendorid=0x2516,productid=0x001a" #CM keyboard
#OPTS="$OPTS -device usb-host,bus=usb-bus.0,vendorid=0x046d,productid=0xc24a" #logitech G600 mouse
# USB 2.0 passthrough
#OPTS="$OPTS -device usb-ehci,id=ehci"
#OPTS="$OPTS -device usb-host,bus=ehci.0,vendorid=0x194f,productid=0x0101" #presonus
# USB 3.0 passthrough (NEC/Renesas) not really used yet
#OPTS="$OPTS -device nec-usb-xhci,id=xhci"
#OPTS="$OPTS -device usb-host,bus=xhci.0,vendorid=0x194f,productid=0x0101" #presonus
#OPTS="$OPTS -device usb-host,bus=xhci.0,vendorid=0x046d,productid=0xc52f" #logitech receiver
#OPTS="$OPTS -device vfio-pci,host=03:00.0"
# Keyboard layout
#OPTS="$OPTS -k en-us"
# Boot priority
OPTS="$OPTS -boot order=c"
# OVMF
cp "/blacknas/vm_win10/ovmf-x64/OVMF_VARS-pure-efi.fd" "/blacknas/vm_win10/my_vars.fd"
OPTS="$OPTS -drive if=pflash,format=raw,readonly,file=/blacknas/vm_win10/ovmf-x64/OVMF_CODE-pure-efi.fd"
OPTS="$OPTS -drive if=pflash,format=raw,file=/blacknas/vm_win10/my_vars.fd"
# System drive
OPTS="$OPTS -drive id=disk0,if=none,cache=unsafe,format=raw,file=/blacknas/vm_win10/hdd.img"
OPTS="$OPTS -device driver=virtio-scsi-pci,id=scsi0"
OPTS="$OPTS -device scsi-hd,drive=disk0"
# Other drive
#OPTS="$OPTS -drive id=disk1,if=none,cache=none,aio=native,format=raw,file=/dev/disk/by-id/ata-Hitachi_HDS721050CLA660_JP1570FR1ZWP7K"
#OPTS="$OPTS -device driver=virtio-scsi-pci,id=scsi1"
#OPTS="$OPTS -device scsi-hd,drive=disk1"
# Other drive 2
#OPTS="$OPTS -drive id=disk2,if=none,cache=none,aio=native,format=raw,file=/dev/disk/by-id/ata-Hitachi_HDS5C3020ALA632_ML0220F30NX2DD"
#OPTS="$OPTS -device driver=virtio-scsi-pci,id=scsi2"
#OPTS="$OPTS -device scsi-hd,drive=disk2"
# Windows 10 Pro installer
#OPTS="$OPTS -drive id=cd0,if=none,format=raw,readonly,file=/blacknas/vm_win10/Windows10.iso"
#OPTS="$OPTS -device driver=ide-cd,bus=ide.0,drive=cd0"
# Virtio driver
OPTS="$OPTS -drive id=virtiocd,if=none,format=raw,file=/blacknas/vm_win10/virtio-win.iso"
OPTS="$OPTS -device driver=ide-cd,bus=ide.1,drive=virtiocd"
# OVMF emits a number of info / debug messages to the QEMU debug console, at
# ioport 0x402. We configure qemu so that the debug console is indeed
# available at that ioport. We redirect the host side of the debug console to
# a file.
#OPTS="$OPTS -global isa-debugcon.iobase=0x402 -debugcon file:/tmp/windows_10_pro.ovmf.log"
# QEMU accepts various commands and queries from the user on the monitor
# interface. Connect the monitor with the qemu process's standard input and
# output.
#OPTS="$OPTS -monitor stdio"
# A USB tablet device in the guest allows for accurate pointer tracking
# between the host and the guest.
#OPTS="$OPTS -device piix3-usb-uhci -device usb-tablet"
# Network
#OPTS="$OPTS -netdev tap,vhost=on,ifname=$VM,script=/usr/local/bin/vm_ifup_brlan,id=brlan"
#OPTS="$OPTS -device virtio-net-pci,mac=52:54:00:xx:xx:xx,netdev=brlan"
OPTS="$OPTS -netdev bridge,id=net0,br=br_vms,helper=/usr/lib/qemu/qemu-bridge-helper -device virtio-net-pci,netdev=net0,id=net0,mac=52:54:00:c9:18:12"
# Disable display
#OPTS="$OPTS -vga qxl"
OPTS="$OPTS -vga none"
OPTS="$OPTS -serial null"
OPTS="$OPTS -parallel null"
OPTS="$OPTS -monitor none"
OPTS="$OPTS -display none"
#OPTS="$OPTS -daemonize"
# QEMU Guest Agent
#OPTS="$OPTS -chardev socket,path=/tmp/qga.sock,server,nowait,id=qga0"
#OPTS="$OPTS -device virtio-serial"
#OPTS="$OPTS -device virtserialport,chardev=qga0,name=org.qemu.guest_agent.0"
virsh nodedev-detach pci_0000_00_14_0
sudo taskset -c 0-5 qemu-system-x86_64 $OPTS
virsh nodedev-reattach pci_0000_00_14_0
#qemu-system-x86_64 $OPTS
#echo $OPTS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment