Skip to content

Instantly share code, notes, and snippets.

@Ethorbit
Last active December 22, 2023 03:35
Show Gist options
  • Save Ethorbit/87574de509c15409076c7830c49ef2d6 to your computer and use it in GitHub Desktop.
Save Ethorbit/87574de509c15409076c7830c49ef2d6 to your computer and use it in GitHub Desktop.
A Proxmox hookscript (/var/lib/vz/snippets/second-gpu.sh) that releases my NVIDIA GPU after the VM stops so that I can display the host terminal.
#!/bin/bash
SECOND_GPU="0000:01:00.0"
# First argument is the vmid
# Second argument is the phase
VMID="$1"
shift
PHASE="$1"
if [ "$PHASE" = "post-stop" ]; then
sleep 2
while [ -d "/sys/bus/pci/drivers/vfio-pci/$SECOND_GPU" ]; do
echo "$SECOND_GPU" > /sys/bus/pci/drivers/vfio-pci/unbind 2>&1
done
while [ ! -d "/sys/bus/pci/drivers/nouveau/$SECOND_GPU" ]; do
echo "$SECOND_GPU" > /sys/bus/pci/drivers/nouveau/bind 2>&1
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment