Advertisement
Guest User

detach-devices.sh

a guest
Dec 30th, 2018
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. ## Kill X and related
  4. systemctl stop lightdm > /dev/null 2>&1
  5. killall cinnamon > /dev/null 2>&1
  6. sleep 2
  7.  
  8. # Kill the console to free the GPU
  9. echo 0 > /sys/class/vtconsole/vtcon0/bind
  10. echo 0 > /sys/class/vtconsole/vtcon1/bind
  11. echo efi-framebuffer.0 > /sys/bus/platform/drivers/efi-framebuffer/unbind
  12.  
  13. # Unload the Kernel Modules that use the GPU
  14. modprobe --remove-dependencies amdgpu
  15. modprobe --remove-dependencies snd_hda_intel
  16.  
  17. virsh nodedev-detach $VIRSH_GPU
  18. virsh nodedev-detach $VIRSH_GPU_AUDIO
  19. virsh nodedev-detach $VIRSH_USB
  20.  
  21. # Load the kernel module
  22. modprobe vfio
  23. modprobe vfio_iommu_type1
  24. modprobe vfio-pci
  25.  
  26. # Detach the GPU from drivers and attach to vfio. Also the usb.
  27. #https://stackoverflow.com/questions/25317520/writing-in-sys-bus-pci-fails
  28. #gpu
  29. sh -c "echo $videoid > /sys/bus/pci/drivers/vfio-pci/new_id"
  30. sh -c "echo $videobusid > /sys/bus/pci/devices/$videobusid/driver/unbind"
  31. sh -c "echo $videobusid > /sys/bus/pci/drivers/vfio-pci/bind"
  32. sh -c "echo $videoid > /sys/bus/pci/drivers/vfio-pci/remove_id"
  33.  
  34. #gpu audio
  35. sh -c "echo $audioid > /sys/bus/pci/drivers/vfio-pci/new_id"
  36. sh -c "echo $audiobusid > /sys/bus/pci/devices/$audiobusid/driver/unbind"
  37. sh -c "echo $audiobusid > /sys/bus/pci/drivers/vfio-pci/bind"
  38. sh -c "echo $audioid > /sys/bus/pci/drivers/vfio-pci/remove_id"
  39.  
  40. #usb
  41. sh -c "echo $usbid > /sys/bus/pci/drivers/vfio-pci/new_id"
  42. sh -c "echo $usbbusid > /sys/bus/pci/devices/$usbbusid/driver/unbind"
  43. sh -c "echo $usbbusid > /sys/bus/pci/drivers/vfio-pci/bind"
  44. sh -c "echo $usbid > /sys/bus/pci/drivers/vfio-pci/remove_id"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement