I have a 3060 Ti as secondary on Ubuntu, and I want it to be used by the host system for stuff that can only be done by an NVIDIA GPU without using it as display (disable it completely), such as CUDA (i.e. Stable Diffusion). However, I also want to be able to use that GPU for passthrough seamlessly to my VMs if needed, and be able to use it again for CUDA after I’m done using it for VM work.
In short, I still need a display cable plugged into the GPU for the VMs, while still be able to use it for CUDA stuff, like Stable Diffusion, when not being used for passthrough.
I have my GPU currently using vfio-pci driver:
vfio-pci.ids=10de:2486,10de:228b
Would the NVIDIA headless driver work?
EDIT: Just tried with headless driver, and here’s what happens:
No output, except for boot splash screen
It screwed my desktop layout
I can see the monitor plugged into the NVIDIA GPU, but no display gets shown (as expected)
I tried to start one of my VMs with GPU passthrough and Virt Manager just hung.
It is possible to make it work, but it is finicky. I had it working previously but now I have trouble rebinding to vfio after using my nvidia card on the host system (I suspect the cause is the driver update to 530).
Which steps did you use exactly? Which distro, kernel, nvidia drivers are you using?
I’m not familiar with the headless driver (I use fedora with the rpmfusion driver), but here is how I reattach the gpu after binding it to vfio on boot (or after shutting down the VM):
Binding to the nvidia driver for xx.0 is not necessary, probing the nvidia module already does this. This is on Wayland, I don’t know if Xorg behaves differently here.
Yes it would affect your current session… The desktop environment attaches to the GPU and the GPU can’t be passed through as long as it is being used. That’s why these guides have you unbind the vtconsole and efi-framebuffer and kill the display manager.
If you try passthrough while some process is using the GPU virtmanager will hang. You can check this with sudo fuser -v /dev/nvidia0
The approach I use for this, is to bind to vfio on boot, then if I need the card in linux I reattach to host using the script I posted above. Important is to reattach only AFTER the display manager has started. Otherwise it sees the GPU and tries to use it.