#!/bin/bash DEV="$1" VENDOR="$2" DEVICE="$3" if [ -z "$DEV" ] || [ -z "$VENDOR" ] || [ -z "$DEVICE" ]; then echo "Usage: $0 " echo "Example: $0 0000:3b:00.0 8086 1520" exit 1 fi # Wait until device exists for i in {1..20}; do [ -e /sys/bus/pci/devices/$DEV ] && break sleep 0.5 done # Unbind from current driver logger -t vfio-bind "Binding device $DEV (vendor: $VENDOR, device: $DEVICE) to vfio-pci" if [ -L /sys/bus/pci/devices/$DEV/driver ]; then logger -t vfio-bind "Unbinding device $DEV from current driver" echo "$DEV" > /sys/bus/pci/devices/$DEV/driver/unbind fi # Tell kernel to prefer vfio-pci logger -t vfio-bind "Setting driver override to vfio-pci for device $DEV" echo vfio-pci > /sys/bus/pci/devices/$DEV/driver_override # Bind to vfio-pci logger -t vfio-bind "Binding device $DEV to vfio-pci driver" echo "$DEV" > /sys/bus/pci/drivers/vfio-pci/bind