Advertisement
Guest User

reattach-devices.sh

a guest
Dec 30th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #check for variable existence in case script was runned independently
  4. if ${VIRSH_GPU+"false"}
  5. then
  6. source config
  7. fi
  8.  
  9. # Unload the vfio module. I am lazy, this leaves the GPU without drivers
  10. modprobe -r vfio-pci
  11. modprobe -r vfio_iommu_type1
  12. modprobe -r vfio
  13.  
  14. # Reload the kernel modules. This loads the drivers for the GPU
  15. modprobe snd_hda_intel
  16. modprobe amdgpu
  17.  
  18. virsh nodedev-reattach $VIRSH_GPU_AUDIO
  19. virsh nodedev-reattach $VIRSH_GPU
  20. virsh nodedev-reattach $VIRSH_USB
  21.  
  22. # Bind the usb
  23. sh -c "echo $usbid > /sys/bus/pci/drivers/xhci_hcd/new_id"
  24. sh -c "echo $usbbusid > /sys/bus/pci/devices/$usbbusid/driver/unbind"
  25. sh -c "echo $usbbusid > /sys/bus/pci/drivers/xhci_hcd/bind"
  26. sh -c "echo $usbid > /sys/bus/pci/drivers/xhci_hcd/remove_id"
  27. ls -la /sys/bus/pci/devices/$usbbusid/
  28.  
  29. # Re-Bind EFI-Framebuffer and Re-bind to virtual consoles
  30. # [Source] [https://github.com/joeknock90/Single-GPU-Passthrough/blob/master/README.md#vm-stop-script]
  31. echo 1 > /sys/class/vtconsole/vtcon0/bind
  32. sleep 1
  33. echo 1 > tee /sys/class/vtconsole/vtcon1/bind
  34. sleep 1
  35.  
  36. # Reload the Display Manager to access X
  37. systemctl start lightdm
  38. sleep 2
  39.  
  40. # Restore the Frame Buffer
  41. echo efi-framebuffer.0 > /sys/bus/platform/drivers/efi-framebuffer/bind
  42. sleep 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement