Last active
September 5, 2023 17:05
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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