With more recent LXD we have the pci
device type which does this for you.
lxc config device add INSTANCE my-device pci address=01:00.0
will attach host PCI device 01:00.0 to the VM called INSTANCE.
If you’re dealing with a GPU or NIC, then it’s best to use the physical
type for either the gpu
or nic
device types respectively. This will perform the same VFIO passthrough but will put them in a different spot on the PCIe bus and in the GPU case will also pass through related devices (built-in USB, sound card, … that may be found on the GPU PCB)