This script takes one or two parameters in any order:
Vendor:Devicei.e.vvvv:ddddDomain:Bus:Device.Functioni.e.dddd:vv:dd.f
and then:
-
If both
Vendor:DeviceandDomain:Bus:Device.Functionwere provided, validate that the requestedVendor:Deviceexists atDomain:Bus:Device.FunctionIf only
Vendor:Devicewas provided, determine the currentDomain:Bus:Device.Functionfor that device.If only
Domain:Bus:Device.Functionwas provided, use it. -
Unbinds all devices that are in the same iommu group as the supplied device from their current driver (except PCIe bridges).
-
Binds to vfio-pci:
- The supplied device.
- All devices that are in the same iommu group.
-
Transfers ownership of the respective iommu group inside /dev/vfio to $SUDO_USER
Suggestions:
-
If you have a single piece of hardware with a given
Vendor:Device, you can call the script like this:vfio-pci-bind.sh Vendor:DeviceThe script will target that device regardless of how the PCI address might change due to the addition or removal of other hardware.
-
If you have multiple pieces of hardware with the same
Vendor:Devicecode, you need to pass the PCI address as well:vfio-pci-bind.sh Vendor:Device Domain:Bus:Device.FunctionThis will ensure the correct instance of the hardware is bound to vfio-pci.
Note: If the PCI address for this device changes as a result of adding or removing hardware, you will need to update the PCI address in this call.
-
For backwards compatibility you can also specify just the PCI address:
vfio-pci-bind.sh Domain:Bus:Device.FunctionNote: If you add or remove hardware, the device associated with that PCI address can change resulting in the wrong device being bound to vfio-pci. Consider passing the
Vendor:Deviceas well.
Script must be executed via sudo!
Devices can be automatically bound to vfio-pci on boot using the supplied 25-vfio-pci-bind.rules udev rules file.
- Copy
vfio-pci-bind.shto/lib/udev/and ensure it is marked executable. - Copy
25-vfio-pci-bind.rulesto/etc/udev/rules.d/ - Edit
/etc/udev/rules.d/25-vfio-pci-bind.rulesand add PCI device matching rules following the examples in the file. - Reboot.
See supplied LICENSE file.