Skip to main content

Resetting GPU

Keep in mind I haven't yet tested this with AMD card

Hookscript example:

#!/bin/bash

if [ $2 == "pre-start" ]
then
    echo "gpu-hookscript: Resetting GPU for Vitual Machine $1"
    echo 1 > /sys/bus/pci/devices/0000\:07\:00.0/remove
    echo 1 > /sys/bus/pci/devices/0000\:07\:00.1/remove
    echo 1 > /sys/bus/pci/devices/0000\:07\:00.2/remove
    echo 1 > /sys/bus/pci/devices/0000\:07\:00.3/remove
    echo 1 > /sys/bus/pci/rescan
fi

As you can see I remove multiple devices, they are basically the audio and USB devices found on the GPU and I just wanted to make sure they are all reset, but I am not 100% confident they are needed.

Note: you have to change the device id to match yours

Then deploy it:

#create snippets folder
mkdir /var/lib/vz/snippets

#create script with content above
nano /var/lib/vz/snippets/gpu-hookscript.sh

#make it executable
chmod +x /var/lib/vz/snippets/gpu-hookscript.sh

#apply script to VM
qm set 100 --hookscript local:snippets/gpu-hookscript.sh

Source: