qemu-virtio-vm.sh 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/bin/bash
  2. ## DEVICE PASSTHROUGH
  3. configfile=/etc/vfio-pci.cfg
  4. vmname="windows10vm"
  5. vfiobind() {
  6. dev="$1"
  7. vendor=$(cat /sys/bus/pci/devices/$dev/vendor)
  8. device=$(cat /sys/bus/pci/devices/$dev/device)
  9. if [ -e /sys/bus/pci/devices/$dev/driver ]; then
  10. echo $dev > /sys/bus/pci/devices/$dev/driver/unbind
  11. fi
  12. echo $vendor $device > /sys/bus/pci/drivers/vfio-pci/new_id
  13. }
  14. if ps -A | grep -q $vmname; then
  15. echo "$vmname is already running." &
  16. exit 1
  17. else
  18. cat $configfile | while read line;do
  19. echo $line | grep ^# >/dev/null 2>&1 && continue
  20. vfiobind $line
  21. done
  22. cp /usr/share/edk2.git/ovmf-x64/OVMF_VARS-pure-efi.fd /tmp/my_vars.fd
  23. ## VM INITIALISATION
  24. qemu-system-x86_64 \
  25. -name $vmname,process=$vmname \
  26. -machine type=q35,accel=kvm \
  27. -cpu host,kvm=off \
  28. -smp 4,sockets=1,cores=4,threads=1 \
  29. -enable-kvm \
  30. -m 3G \
  31. -mem-path /run/hugepages/kvm \
  32. -mem-prealloc \
  33. -balloon none \
  34. -rtc clock=host,base=localtime \
  35. -vga qxk \
  36. -serial none \
  37. -parallel none \
  38. -soundhw hda \
  39. -device vfio-pci,host=01:00.0,multifunction=on \
  40. -device vfio-pci,host=01:00.1 \
  41. -drive if=pflash,format=raw,readonly,file=/usr/share/edk2.git/ovmf-x64/OVMF_CODE-pure-efi.fd \
  42. -drive if=pflash,format=raw,file=/tmp/my_vars.fd \
  43. -boot order=dc \
  44. -device virtio-scsi-pci,id=scsi \
  45. -drive id=disk0,if=virtio,cache=none,format=raw,file=<storage>.img \
  46. -drive file=<windows>.iso,id=isocd,format=raw,if=none -device scsi-cd,drive=isocd \
  47. -drive file=<virtio-win>.iso,id=virtiocd,format=raw,if=none -device ide-cd,bus=ide.1,drive=virtiocd \
  48. -netdev type=tap,id=net0,ifname=tap0,vhost=on \
  49. -device virtio-net-pci,netdev=net0,mac=00:16:3e:00:01:01
  50. exit 0
  51. fi