The method described in this gist has been deprecated/superceeded by kiler129/early-vfio-pci-isolate tool.
It is more robust, configurable, and doesn't hack around scripts that are sometimes overwritten by system updates. The tool uses similar methods to the ones described below, but extends the capabilities by e.g. easy NVMe passthrough by S/N.
The description below has been preserved for historical context. At the time of writing, the tool above has been tested for ~6 months across multiple systems.
You're running a KVM-based virtualization. You want to do PCI/PCIe passthrough of some device. You don't want it to attach to the host OS at all.
Your device looks like that:
00:1f.2 SATA controller [0106]: Intel Corporation 6 Series/C200 Series Chipset Family SATA AHCI Controller [8086:1c02] (rev 05)
	Subsystem: Hewlett-Packard Company 6 Series/C200 Series Chipset Family 6 port Desktop SATA AHCI Controller [103c:330d]
	Kernel driver in use: ahci
	Kernel modules: ahci
Usually the solutions are simple:
- If you have only one device listing some module in 
Kernel modules(e.g.nvidiafb) you can add it to/etc/modprobe.d/some-file.confasblacklist nvidiafb - If you have multiple and they're normal devices you just add 
options vfio-pci ids=8086:1c02to some file in/etc/modprobe.d/(make sure to use the id in[...]and not pci location00:1f.2) 
However, these will not work if your device is handled by something loaded very very VERY early... like a driver for your second SATA controller.
- You cannot blacklist 
ahci(like in example here) because you will prevent all controllers from working (=no boot volume) - You cannot use 
modprobe.dto set options becausevfio-pciloads waaaaay too late. 
There are two prerequisites:
vfio-pcimust be availbale before rootfs is attachedvfio-pcimust load beforeahciloads
The first is simple:
- add 
vfio-pcito/etc/initramfs-tools/modules - update initramfs: 
update-initramfs -u -k $(uname -r) - Proxmox on UEFI: if you're using Proxmox 7 booted using UEFI mode you also need to run 
proxmox-boot-tool refresh - it will place the module in 
initramfsdisk (in/etc/conf/modules) 
The second is more complicated:
- entry in 
/etc/initramfs-tools/moduleswill loadvfio-pcibefore the rootfs is mounted - however, 
/etc/conf/modulesfrom ramdisk is loaded after some scripts (see/initin ramdisk) - these scripts (
scripts/init-top/) load some drivers... andudev... andudevloadsahci - solution:
- create 
/usr/share/initramfs-tools/scripts/init-top/load_vfio-pciwith#!/bin/sh modprobe vfio-pci ids=8086:1c02 chmod +x /usr/share/initramfs-tools/scripts/init-top/load_vfio-pci- edit 
/usr/share/initramfs-tools/scripts/init-top/udevand changePREREQS=""toPREREQS="load_vfio-pci" 
 - create 
 - update initramfs: 
update-initramfs -u -k $(uname -r) - Proxmox on UEFI: if you're using Proxmox 7 booted using UEFI mode you also need to run 
proxmox-boot-tool refresh - note: this will not work if placed in "standard place" (
/etc/initramfs-tools/scripts...) as dependencies are not cross-directory and/usr/sharecomes first 
Without the mod:
# lspci -knn
...
00:1f.2 SATA controller [0106]: Intel Corporation 6 Series/C200 Series Chipset Family SATA AHCI Controller [8086:1c02] (rev 05)
	Subsystem: Hewlett-Packard Company 6 Series/C200 Series Chipset Family 6 port Desktop SATA AHCI Controller [103c:330d]
	Kernel driver in use: ahci
	Kernel modules: ahci
With the mod:
# lspci -knn
...
00:1f.2 SATA controller [0106]: Intel Corporation 6 Series/C200 Series Chipset Family SATA AHCI Controller [8086:1c02] (rev 05)
	Subsystem: Hewlett-Packard Company 6 Series/C200 Series Chipset Family 6 port Desktop SATA AHCI Controller [103c:330d]
	Kernel driver in use: vfio-pci
	Kernel modules: ahci
You are the best!!!
a day of web and forum research... without solution!
your explanation was very simple and perfectly understandable, thanks a lot from Italy!!!