Skip to content

Instantly share code, notes, and snippets.

@cspicer
Last active September 19, 2022 23:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cspicer/ff78616c98fe68965bbf to your computer and use it in GitHub Desktop.
Save cspicer/ff78616c98fe68965bbf to your computer and use it in GitHub Desktop.
vfio-bind for KVM passthrough
#!/bin/bash
modprobe vfio-pci
for dev in "$@"; do
vendor=$(cat /sys/bus/pci/devices/$dev/vendor)
device=$(cat /sys/bus/pci/devices/$dev/device)
if [ -e /sys/bus/pci/devices/$dev/driver ]; then
echo $dev > /sys/bus/pci/devices/$dev/driver/unbind 2>/dev/null
fi
echo $vendor $device > /sys/bus/pci/drivers/vfio-pci/new_id 2>/dev/null
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment