Advertisement
Guest User

windows-install modified 181227

a guest
Dec 28th, 2018
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.43 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Check if the script is executed as root
  4. if [ "$EUID" -ne 0 ]
  5. then echo "Please run as root"
  6. exit 1
  7. fi
  8. # END Check if you are sudo
  9.  
  10. source config
  11.  
  12. # Memory lock limit
  13. if [ $(ulimit -a | grep "max locked memory" | awk '{print $6}') != $(( $(echo $RAM | tr -d 'G')*1048576+10 )) ]; then
  14. ulimit -l $(( $(echo $RAM | tr -d 'G')*1048576+10 ))
  15. fi
  16.  
  17. ## Kill X and related
  18. systemctl stop lightdm > /dev/null 2>&1
  19. killall cinnamon > /dev/null 2>&1
  20. sleep 2
  21.  
  22. # Kill the console to free the GPU
  23. echo 0 > /sys/class/vtconsole/vtcon0/bind
  24. echo 0 > /sys/class/vtconsole/vtcon1/bind
  25. echo efi-framebuffer.0 > /sys/bus/platform/drivers/efi-framebuffer/unbind
  26.  
  27. # Unload the Kernel Modules that use the GPU
  28. modprobe --remove-dependencies amdgpu
  29. modprobe --remove-dependencies snd_hda_intel
  30.  
  31. virsh nodedev-detach $VIRSH_GPU
  32. virsh nodedev-detach $VIRSH_GPU_AUDIO
  33.  
  34. # Load the kernel module
  35. modprobe vfio
  36. modprobe vfio_iommu_type1
  37. modprobe vfio-pci
  38.  
  39. # Detach the GPU from drivers and attach to vfio. Also the usb.
  40. #https://stackoverflow.com/questions/25317520/writing-in-sys-bus-pci-fails
  41. #gpu
  42. sh -c "echo $videoid > /sys/bus/pci/drivers/vfio-pci/new_id"
  43. sh -c "echo $videobusid > /sys/bus/pci/devices/$videobusid/driver/unbind"
  44. sh -c "echo $videobusid > /sys/bus/pci/drivers/vfio-pci/bind"
  45. sh -c "echo $videoid > /sys/bus/pci/drivers/vfio-pci/remove_id"
  46.  
  47. #gpu audio
  48. sh -c "echo $audioid > /sys/bus/pci/drivers/vfio-pci/new_id"
  49. sh -c "echo $audiobusid > /sys/bus/pci/devices/$audiobusid/driver/unbind"
  50. sh -c "echo $audiobusid > /sys/bus/pci/drivers/vfio-pci/bind"
  51. sh -c "echo $audioid > /sys/bus/pci/drivers/vfio-pci/remove_id"
  52.  
  53. # QEMU (VM) command
  54. qemu-system-x86_64 -runas $USER -enable-kvm \
  55. -nographic -vga none -parallel none -serial none \
  56. -enable-kvm \
  57. -m $RAM \
  58. -cpu host,kvm=off,hv_relaxed,hv_spinlocks=0x1fff,hv_time,hv_vapic,hv_vendor_id=0xDEADBEEFFF \
  59. -rtc clock=host,base=localtime \
  60. -smp $CORES,sockets=1,cores=$CORES,threads=0 \
  61. -device vfio-pci,host=$IOMMU_GPU,multifunction=on,x-vga=on,romfile=$VBIOS1 \
  62. -device vfio-pci,host=$IOMMU_GPU_AUDIO \
  63. -device virtio-net-pci,netdev=n1 \
  64. -netdev user,id=n1 \
  65. -drive if=pflash,format=raw,readonly,file=$OVMF \
  66. -drive media=cdrom,file=$ISO,id=iso_install,if=none \
  67. -device ide-cd,drive=iso_install \
  68. -drive media=cdrom,file=$VIRTIO,id=virtiocd1,if=none \
  69. -device ide-cd,drive=virtiocd1 \
  70. -drive file=$IMG,if=none,id=rootfs,format=raw \
  71. -device virtio-blk-pci,drive=rootfs &> qemu_start.log &
  72.  
  73. # END QEMU (VM) command
  74.  
  75. # Wait for QEMU to finish before continue
  76. wait
  77. sleep 1
  78.  
  79. # Unload the vfio module. I am lazy, this leaves the GPU without drivers
  80. modprobe -r vfio-pci
  81. modprobe -r vfio_iommu_type1
  82. modprobe -r vfio
  83.  
  84. # Reload the kernel modules. This loads the drivers for the GPU
  85. modprobe snd_hda_intel
  86. modprobe amdgpu
  87.  
  88. virsh nodedev-reattach $VIRSH_GPU_AUDIO
  89. virsh nodedev-reattach $VIRSH_GPU
  90.  
  91. # Re-Bind EFI-Framebuffer and Re-bind to virtual consoles
  92. # [Source] [https://github.com/joeknock90/Single-GPU-Passthrough/blob/master/README.md#vm-stop-script]
  93. echo 1 > /sys/class/vtconsole/vtcon0/bind
  94. sleep 1
  95. echo 1 > tee /sys/class/vtconsole/vtcon1/bind
  96. sleep 1
  97.  
  98. # Reload the Display Manager to access X
  99. systemctl start lightdm
  100. sleep 2
  101.  
  102. # Restore the Frame Buffer
  103. echo efi-framebuffer.0 > /sys/bus/platform/drivers/efi-framebuffer/bind
  104. sleep 1
  105.  
  106. # Restore ulimit
  107. ulimit -l $ULIMIT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement