Skip to content

Instantly share code, notes, and snippets.

@tbr
Last active September 5, 2023 17:05
Show Gist options
  • Save tbr/eba46f0a219b9f1e1c388fcd23efe442 to your computer and use it in GitHub Desktop.
Save tbr/eba46f0a219b9f1e1c388fcd23efe442 to your computer and use it in GitHub Desktop.
Proxmox PCIe passthru with vfio-pci by exact device address (rather than per complete kernel module and VID/DEV)
#!/bin/sh
# Place in /etc/initramfs-tools/scripts/init-top (+x)
#
# This way of PCIe passthru allows for example to select a single NIC
# for a VM, while allowing other NICs to be still used by Proxmox.
#
# In my case, to passthru one SFP+ slot of a dual NIC card.
#
PREREQ=""
prereqs()
{
echo "$PREREQ"
}
case $1 in
prereqs)
prereqs
exit 0
;;
esac
. /scripts/functions
# Exclude PCIe devices by address, rather than ID.
DEVS="0000:02:00.0 0000:04:00.1 0000:07:00.0 0000:07:00.1"
if [ ! -z "$(ls -A /sys/class/iommu)" ]; then
for DEV in $DEVS; do
echo "vfio-pci" > /sys/bus/pci/devices/$DEV/driver_override
log_success_msg "PCIe $DEV marked for passthrough"
done
fi
modprobe -i vfio-pci
#!/bin/sh
# Place in /etc/initramfs-tools/hooks/ (+x)
#
PREREQ=""
prereqs()
{
echo "$PREREQ"
}
case $1 in
prereqs)
prereqs
exit 0
;;
esac
. /usr/share/initramfs-tools/hook-functions
# Begin real processing below this line
# Add the required vfio* modules.
manual_add_modules vfio
manual_add_modules vfio_iommu_type1
manual_add_modules vfio_pci
manual_add_modules vfio_virqfd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment