Advertisement
Guest User

windows-install modified

a guest
Dec 24th, 2018
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.09 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 -r nvidia_drm
  29. #modprobe -r nvidia_modeset
  30. #modprobe -r nvidia
  31. modprobe -r snd_hda_intel
  32. modprobe -r amdgpu
  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. #no such file or dir
  44. sh -c "echo $videobusid > /sys/bus/pci/devices/$videobusid/driver/unbind"
  45. sh -c "echo $videobusid > /sys/bus/pci/drivers/vfio-pci/bind"
  46. sh -c "echo $videoid > /sys/bus/pci/drivers/vfio-pci/remove_id"
  47.  
  48. #gpu audio
  49. sh -c "echo $audioid > /sys/bus/pci/drivers/vfio-pci/new_id"
  50.  
  51. #no such file or dir
  52. sh -c "echo $audiobusid > /sys/bus/pci/devices/$audiobusid/driver/unbind"
  53. sh -c "echo $audiobusid > /sys/bus/pci/drivers/vfio-pci/bind"
  54. sh -c "echo $audioid > /sys/bus/pci/drivers/vfio-pci/remove_id"
  55.  
  56. #usb
  57. #sh -c "echo $usbid > /sys/bus/pci/drivers/vfio-pci/new_id"
  58.  
  59. #no such file or dir
  60. #sh -c "echo $usbbusid > /sys/bus/pci/devices/$usbbusid/driver/unbind"
  61. #sh -c "echo $usbbusid > /sys/bus/pci/drivers/vfio-pci/bind"
  62. #sh -c "echo $usbid > /sys/bus/pci/drivers/vfio-pci/remove_id"
  63.  
  64. # QEMU (VM) command
  65. qemu-system-x86_64 -runas $USER -enable-kvm \
  66. -nographic -vga none -parallel none -serial none \
  67. -enable-kvm \
  68. -m $RAM \
  69. -cpu host,kvm=off,hv_relaxed,hv_spinlocks=0x1fff,hv_time,hv_vapic,hv_vendor_id=0xDEADBEEFFF \
  70. -rtc clock=host,base=localtime \
  71. -smp $CORES,sockets=1,cores=$CORES,threads=0 \
  72. -device vfio-pci,host=$IOMMU_GPU,multifunction=on,x-vga=on,romfile=$VBIOS \
  73. -device vfio-pci,host=$IOMMU_GPU_AUDIO \
  74. -device virtio-net-pci,netdev=n1 \
  75. -netdev user,id=n1 \
  76. -drive if=pflash,format=raw,readonly,file=$OVMF \
  77. -drive media=cdrom,file=$ISO,id=virtiocd1,if=none \
  78. -device ide-cd,bus=ide.1,drive=virtiocd1 \
  79. -drive media=cdrom,file=$VIRTIO,id=virtiocd2,if=none \
  80. -device ide-cd,bus=ide.1,drive=virtiocd2 \
  81. -device ide-drive,bus=ide.1,drive=rootfs \
  82. -drive id=rootfs,if=none,file=$IMG,format=raw > qemu_start.log &
  83.  
  84.  
  85. #-device vfio-pci,host=$IOMMU_USB \
  86. # END QEMU (VM) command
  87.  
  88. # Wait for QEMU to finish before continue
  89. wait
  90. sleep 1
  91.  
  92. # Unload the vfio module. I am lazy, this leaves the GPU without drivers
  93. modprobe -r vfio-pci
  94. modprobe -r vfio_iommu_type1
  95. modprobe -r vfio
  96.  
  97. # Reload the kernel modules. This loads the drivers for the GPU
  98. modprobe snd_hda_intel
  99. #modprobe nvidia_drm
  100. #modprobe nvidia_modeset
  101. #modprobe nvidia
  102. modprobe amdgpu
  103.  
  104. # Bind the usb
  105. #sh -c "echo $usbid > /sys/bus/pci/drivers/xhci_hcd/new_id"
  106. #sh -c "echo $usbbusid > /sys/bus/pci/devices/$usbbusid/driver/unbind"
  107. #sh -c "echo $usbbusid > /sys/bus/pci/drivers/xhci_hcd/bind"
  108. #sh -c "echo $usbid > /sys/bus/pci/drivers/xhci_hcd/remove_id"
  109. #ls -la /sys/bus/pci/devices/$usbbusid/
  110.  
  111. # Re-Bind EFI-Framebuffer and Re-bind to virtual consoles
  112. # [Source] [https://github.com/joeknock90/Single-GPU-Passthrough/blob/master/README.md#vm-stop-script]
  113. echo 1 > /sys/class/vtconsole/vtcon0/bind
  114. sleep 1
  115. echo 1 > tee /sys/class/vtconsole/vtcon1/bind
  116. sleep 1
  117.  
  118. # Reload the Display Manager to access X
  119. systemctl start lightdm
  120. sleep 2
  121.  
  122. # Restore the Frame Buffer
  123. echo efi-framebuffer.0 > /sys/bus/platform/drivers/efi-framebuffer/bind
  124. sleep 1
  125.  
  126. # Restore ulimit
  127. ulimit -l $ULIMIT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement