Switch GPU Mode (VM ↔ LXC)
Move an assigned GPU between VM passthrough and LXC sharing. ProxMenux manages the host driver binding, VFIO configuration, module settings and initramfs, and asks how to handle affected guests. Review those choices and verify the resulting configuration after reboot.
What this does
vfio-pci (reserved for a VM) or bound to its native driver (i915 / amdgpu / nvidia) so the host + LXCs can share it. Switch GPU Mode flips between those two without you having to hand-edit vfio.conf, manage blacklists, or remember which VM / LXC lines point to the card. It also warns you cleanly if a workload still references the GPU so you don't end up with a broken VM at boot.Switch Mode
Ready for LXC containers
Native driver active
Switch Mode
Ready for VM passthrough
VFIO-PCI driver active
When should I use this?
Use this script when a GPU is already assigned and you want to move it:
| Situation | Use this page? |
|---|---|
| GPU is free — never assigned. Want to give it to a VM. | No — use Add GPU to VM |
| GPU is free — never assigned. Want to give it to an LXC. | No — use Add GPU to LXC |
GPU is in a VM via vfio-pci, I want to use it from an LXC instead. | Yes — this page. |
| GPU is shared with an LXC, I want to dedicate it to a VM. | Yes — this page. |
| I just want to completely unbind a GPU from everything. | LXC mode restores host-driver ownership; the VM conflict policy can remove hostpci entries, but LXC device entries must be removed separately. This does not leave the GPU unbound from every driver. |
Before you start
- A GPU already assigned — either in a VM via VFIO or attached to at least one LXC. If you haven't assigned it yet, start from Add GPU to VM / LXC instead.
- IOMMU must be active on the host when switching to VM mode. Firmware settings and kernel support both matter. If
intel_iommu=onoramd_iommu=onis missing from the running kernel, the script adds it withiommu=ptto/etc/kernel/cmdline(ZFS-root marker) or/etc/default/grub, then runsproxmox-boot-tool refreshorupdate-grub. Check any warnings and reboot when prompted.dmesg | grep -i 'IOMMU enabled' | head -1 - Plan for a reboot. Persistent driver and boot changes may require rebuilding initramfs and rebooting. The script presents a reboot prompt at the end.
- Know which VMs / LXCs are using the GPU. The script will find them and ask what to do with each, but it's faster if you already know the list.
Not all GPUs are safe to pass to a VM
8086:5a84 and 8086:5a85 under its compatibility policy. If a selected GPU matches, it stops the VM-mode switch and returns to GPU selection, or exits when it is the only GPU. This blocklist does not prevent switching to LXC mode; other checks can still apply.Running the script
Open ProxMenux on the host, go to Hardware: GPUs and Coral-TPU → Switch GPU Mode (VM ↔ LXC).

How the script runs
GPU selection and direction are reviewed before the main switch. A separate stale-VFIO cleanup can ask for confirmation earlier, and affected guests have their own conflict prompts. Read each confirmation: there is not one final confirmation covering every possible change.
┌─────────────────────────────────────────────┐
│ PHASE 1 — Detect, select, plan │
│ (nothing touched yet) │
└──────────────────┬──────────────────────────┘
▼
lspci detects every GPU + current driver
(vfio-pci, nvidia, amdgpu, i915, …)
│
▼
User selects GPU(s) to switch
(checklist; auto-selects if only one)
│
▼
Uniform current mode check
├─ All in VM mode → target = LXC
├─ All in LXC mode → target = VM
└─ Mixed → reject, reselect
│
▼
Validations
├─ SR-IOV VF / active PF? → block
├─ Target = VM and blocked ID? → block
└─ IOMMU parameter present? → auto-add to boot
cmdline if missing
│
▼
Find affected workloads
├─ LXC configs referencing the GPU
└─ VM configs with hostpci for the GPU
(precise BDF regex, no substring false-positives)
│
▼
Conflict policy per affected workload
┌──────────────────────────────────────┐
│ Keep config, disable onboot │
│ └─ safest; workload stays defined │
│ but won't auto-start broken │
│ Remove GPU lines from config │
│ └─ clean; workload works without │
│ the GPU after the switch │
└──────────────────────────────────────┘
│
▼
If target = LXC (leaving VM mode):
└─ Orphan audio cascade
(offer to remove companion audio
hostpci + clean vfio.conf if the
audio ID isn't used by any other VM)
│
▼
Confirmation summary
(target mode + affected workloads +
host changes about to happen)
│
┌─────── Cancel OR Confirm ────┐
▼ ▼
Exit, nothing ┌──────────────────┴──────────────────┐
was changed │ PHASE 2 — Apply │
└──────────────────┬──────────────────┘
▼
Target = VM (bind to vfio-pci):
├─ /etc/modprobe.d/vfio.conf
│ add vendor:device + disable_vga=1
├─ /etc/modprobe.d/blacklist.conf
│ add type-specific blacklists
├─ /etc/modules
│ add vfio-pci, vfio
├─ NVIDIA: sanitize host stack
│ (disable udev rule, hard-blacklist)
└─ AMD: softdep vfio-pci
Target = LXC (back to native driver):
├─ /etc/modprobe.d/vfio.conf
│ drop vendor:device IDs for this GPU
│ (delete line if now empty)
├─ /etc/modprobe.d/blacklist.conf
│ drop type blacklists if no GPU of
│ that type remains in vfio.conf
├─ /etc/modules
│ drop vfio-pci if no GPU in vfio.conf
└─ NVIDIA: restore host stack
(re-enable udev, drop hard-blacklist)
│
▼
Apply workload conflict policy
(pct set onboot=0 OR sed hostpci/dev
lines out of VM/LXC configs)
│
▼
update-initramfs -u -k all
(only if host config actually changed)
│
▼
Reboot prompt — required for the new
binding to take effectWalking through the flow
Detect GPUs and their current binding
The script scans every VGA / 3D / Display controller on the host and inspects /sys/bus/pci/devices/*/driver to find the current kernel driver. You'll see each GPU labelled with its name, PCI slot and current driver binding — so you can tell at a glance which mode it's in.

Pick the GPU(s) to switch
Single GPU → auto-selected. Multiple GPUs → checklist. You can tick several, but they must all be in the same current mode — otherwise the script can't pick a target mode for the batch and you get a "mixed mode" warning asking you to narrow the selection.
Batching switches
Review the proposed direction
Based on the current mode, the script proposes the opposite as target:
- VM → LXC: unbind from
vfio-pci, let the native driver (nvidia,amdgpu,i915) reclaim the card so LXCs can share it. On NVIDIA, the per-BDF entry is removed from/etc/udev/rules.d/10-proxmenux-vfio-bind.rulesso the nvidia module reclaims the GPU after reboot. - LXC → VM: prepares
vfio-pciownership. AMD / Intel use native-driver blacklisting andoptions vfio-pci ids=…. For NVIDIA,nvidiais globally blacklisted only when every host NVIDIA GPU is in VFIO; otherwise per-BDF rules setdriver_override=vfio-pcifor the affected IOMMU-group devices, and NVIDIA GPUs outside those groups keepnvidia. Review every group member before switching.
Confirm the direction or cancel.
Conflict policy per affected workload
The script checks /etc/pve/lxc/*.conf for GPU-device references by driver family, and /etc/pve/qemu-server/*.conf for PCI assignments. LXC detection is not a precise per-card BDF match. Review the detected guests and choose how to handle each:
| Policy | Effect | When to pick |
|---|---|---|
| Keep config, disable onboot | pct set CTID -onboot 0 (or qm set VMID -onboot 0). GPU entries stay in the configuration. | You plan to come back to this VM/LXC once the GPU is back in its original mode. Safe default. |
| Remove GPU from config | Removes identified hostpci / dev entries and supported legacy device references. | Choose this if the guest should operate without the GPU. Check its application settings first: CPU fallback is application-dependent, and removing the device does not automatically reconfigure the app. |

Orphan audio cleanup (only when leaving VM mode)
Many dedicated NVIDIA / AMD GPUs expose HDMI audio at function .1 of the same slot; additional audio devices may also have been assigned. Removing the GPU can leave obsolete hostpci audio entries in the VM. Review which devices should remain assigned.
The script discovers them (precise BDF match, no substring false-positives) and shows a checklist so you can remove them cleanly. It also cleans their vendor:device IDs from /etc/modprobe.d/vfio.conf — but only if no other VM still uses those audio IDs.
Apply host + workload changes
Once you confirm, the script writes the host-side changes — vfio.conf, blacklist, modules, and (for NVIDIA) the per-BDF udev rule at /etc/udev/rules.d/10-proxmenux-vfio-bind.rules plus the BDF state at /etc/proxmenux/vfio-bind.bdfs. It also applies the chosen conflict policy to each affected VM/LXC. If the host config actually changed, it runs update-initramfs -u -k all followed by proxmox-boot-tool refresh; otherwise both are skipped.
Reboot
The new GPU binding only takes effect after a reboot. The script prompts you; you can reboot now or later, but don't start the target VM/LXC until the host has rebooted — otherwise the GPU is still held by the previous driver.

Manual inspection
Before a VM → LXC switch, inspect the driver and existing per-BDF policy. This NVIDIA example uses vendor:device 10de:2204; adapt it to your card. These commands inspect state; the script also manages affected guests and IOMMU-group members.
# Inspect this example GPU; replace the ID with your card
lspci -nnk -d 10de:2204
# Inspect the persistent per-BDF NVIDIA policy
cat /etc/proxmenux/vfio-bind.bdfs
cat /etc/udev/rules.d/10-proxmenux-vfio-bind.rulesBefore LXC → VM, inspect the selected PCI address and its IOMMU group. Replace the example address with yours and review all group members before assigning devices.
# Replace this example PCI address with your selected GPU
lspci -nnk -s 0000:01:00.0
readlink /sys/bus/pci/devices/0000:01:00.0/iommu_group
# List all group members and review them before assignment
find /sys/kernel/iommu_groups/ -type l | sort -VOnly one VM can use a given vfio-pci GPU at a time
hostpci entries with the same PCI slot in two VMs is valid config but only one of the VMs can start with the GPU — the second one will fail. The ProxMenux conflict policy step is exactly about avoiding this trap.Verification after reboot
# Inspect the selected PCI address (replace this example)
lspci -nnk -s 0000:01:00.0
# LXC mode: the supported native driver should own the card
# VM mode: vfio-pci should own the card
# NVIDIA userspace/module consistency check
nvidia-smiTroubleshooting
GPU still shows vfio-pci after switching to LXC mode
update-initramfs and the reboot completed. lsmod | grep vfio only lists modules. For AMD / Intel inspect vfio.conf; for NVIDIA inspect /etc/proxmenux/vfio-bind.bdfs and /etc/udev/rules.d/10-proxmenux-vfio-bind.rules. Correct stale policy before running update-initramfs -u -k all and rebooting.A VM won't start after switching a GPU to LXC mode
hostpci references. The Remove GPU from config policy can remove them during the intended switch; inspect the proposed direction before rerunning the script so you do not reverse the mode unintentionally. Alternatively, remove the obsolete assignment in Proxmox with the VM stopped.# Inspect the VM configuration; replace VMID with the numeric ID
qm config VMID
# With the VM stopped, remove only the obsolete PCI assignment
# in the Proxmox Hardware panel, after identifying its hostpci entrynvidia-smi fails with 'Driver/library version mismatch' after going back to LXC
modprobe -r nvidia and modprobe nvidia requires stopped GPU clients and may fail while dependent modules are in use.Install log
/tmp/proxmenux_gpu_switch_mode.log on the host. Attach it when asking for help on GitHub.Related
- Add GPU to VM (Passthrough) — first-time VM mode setup.
- Add GPU to LXC — first-time LXC mode setup.
- Install NVIDIA Drivers (Host) — required for LXC mode on NVIDIA GPUs.
- ProxMenux Monitor — Hardware tab — the Graphics Cards section where each GPU shows its current mode and exposes the inline switch control.
- GPU Passthrough commands — quick command reference.