Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- ## Kill X and related
- systemctl stop lightdm > /dev/null 2>&1
- killall cinnamon > /dev/null 2>&1
- sleep 2
- # Kill the console to free the GPU
- echo 0 > /sys/class/vtconsole/vtcon0/bind
- echo 0 > /sys/class/vtconsole/vtcon1/bind
- echo efi-framebuffer.0 > /sys/bus/platform/drivers/efi-framebuffer/unbind
- # Unload the Kernel Modules that use the GPU
- modprobe --remove-dependencies amdgpu
- modprobe --remove-dependencies snd_hda_intel
- virsh nodedev-detach $VIRSH_GPU
- virsh nodedev-detach $VIRSH_GPU_AUDIO
- virsh nodedev-detach $VIRSH_USB
- # Load the kernel module
- modprobe vfio
- modprobe vfio_iommu_type1
- modprobe vfio-pci
- # Detach the GPU from drivers and attach to vfio. Also the usb.
- #https://stackoverflow.com/questions/25317520/writing-in-sys-bus-pci-fails
- #gpu
- sh -c "echo $videoid > /sys/bus/pci/drivers/vfio-pci/new_id"
- sh -c "echo $videobusid > /sys/bus/pci/devices/$videobusid/driver/unbind"
- sh -c "echo $videobusid > /sys/bus/pci/drivers/vfio-pci/bind"
- sh -c "echo $videoid > /sys/bus/pci/drivers/vfio-pci/remove_id"
- #gpu audio
- sh -c "echo $audioid > /sys/bus/pci/drivers/vfio-pci/new_id"
- sh -c "echo $audiobusid > /sys/bus/pci/devices/$audiobusid/driver/unbind"
- sh -c "echo $audiobusid > /sys/bus/pci/drivers/vfio-pci/bind"
- sh -c "echo $audioid > /sys/bus/pci/drivers/vfio-pci/remove_id"
- #usb
- sh -c "echo $usbid > /sys/bus/pci/drivers/vfio-pci/new_id"
- sh -c "echo $usbbusid > /sys/bus/pci/devices/$usbbusid/driver/unbind"
- sh -c "echo $usbbusid > /sys/bus/pci/drivers/vfio-pci/bind"
- sh -c "echo $usbid > /sys/bus/pci/drivers/vfio-pci/remove_id"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement