Add GPU to LXC

Hardware: GPUs and Coral-TPU~10 minView script

Share one or more GPUs with a Proxmox LXC container. The host keeps using the GPU normally — the container just gets access through device nodes. Works with Intel iGPUs (Quick Sync / VA-API), AMD cards (Mesa / ROCm), and NVIDIA (CUDA / NVENC).

What this does

Adds dev<N> entries to /etc/pve/lxc/<ctid>.conf for applicable /dev/dri/*, /dev/kfd or /dev/nvidia* nodes. It starts the container, installs userspace packages for its distribution and, for Intel/AMD, aligns the video and render groups. Application acceleration still requires compatible hardware, libraries and app configuration.

LXC sharing vs VM passthrough

LXC containers share the host kernel, so they can share the host's GPU without taking it over. That's a big difference from VMs: with VM passthrough the GPU is exclusive to one VM and the host can't use it. With LXC, multiple containers plus the host can all hit the same GPU at once.

FeatureLXC (this page)VM
Host keeps using the GPU?YesNo — exclusive to the VM
Multiple containers sharing one GPU?YesNo
Requires IOMMU / VFIO on the host?NoYes
Reboot required?Usually no (just restart the CT)When host driver or IOMMU setup changes; not for every VM assignment
Guest operating systemsOnly Linux (LXC is Linux-only)Supported guest OS with a compatible GPU driver

Before you start

  • A GPU on the host — Intel iGPU, AMD dGPU or APU, or an NVIDIA card. The script auto-detects all three via lspci.
    lspci | grep -iE 'VGA|3D|Display'
  • The GPU is NOT bound to vfio-pci. If the GPU is currently assigned to a VM via passthrough, it's invisible to the host kernel driver and the LXC can't use it. The script detects this and offers to run Switch GPU Mode for you.
  • For NVIDIA only: the NVIDIA host driver must already be installed — ProxMenux needs to match the container's userspace libs to the host version. If you haven't done it yet, run Install NVIDIA Drivers on the Host first.
    nvidia-smi
  • An existing LXC container. The script does not create one. Both privilege modes are supported; a privileged container is not universally required. Device entries and the application’s numeric group permissions still need to match.

Works on both privileged and unprivileged containers

The script writes dev<N> entries to the LXC config and, on unprivileged containers, aligns the video and render GIDs between host and container so the GPU device nodes are reachable from inside without you having to hand-edit lxc.idmap.

Running the installer

Open ProxMenux on the host, go to Hardware: GPUs and Coral-TPU → Add GPU to LXC.

Menu entry for 'Add GPU to LXC' inside Hardware: GPUs and Coral-TPU

How the script runs

Select the container and GPU families, then pass the checks. Processing then stops the container and changes its configuration; there is no additional final confirmation. Optional VFIO cleanup has its own confirmation and can change the host earlier.

Walking through the flow

Step 1

Detect host GPUs

The script scans lspci for VGA / 3D / Display controllers matching Intel, AMD or NVIDIA. For NVIDIA it also verifies the nvidia kernel module is loaded and nvidia-smi works — the host driver version it reports will be used to pick the right .run installer for the container.

NVIDIA not ready?

If NVIDIA is detected but the module isn't loaded, the script won't offer the NVIDIA path. Run Install NVIDIA Drivers on the Host first (and reboot), then come back.
Step 2

Pick an LXC container

Lists eligible LXC containers by ID and name; OCI containers are excluded and use OCI manager Apps for devices. The container is stopped if running, started for driver installation and normally returned to its original running/stopped state.

Dialog listing existing LXC containers to choose from
Step 3

Select the GPU(s) to add

The checklist selects detected vendor families, not an isolated PCI device. Intel/AMD add the visible DRI nodes used by the script; NVIDIA adds its available device nodes, potentially covering multiple cards. One detected family is selected automatically. Verify the resulting device list, particularly on multi-GPU hosts.

Checklist showing detected GPUs (Intel / AMD / NVIDIA) with vendor and PCI address
Step 4

Pre-flight checks

Dialog offering to run Switch GPU Mode when the selected GPU is still bound to vfio-pci for VM passthrough

Three checks, any of which can block or redirect you:

  • SR-IOV guard. This assistant blocks a selected VF or PF with active VFs. That is a limitation of its broad device selection, not a universal prohibition on SR-IOV with LXC; configure those devices separately.
  • Bound to vfio-pci. If the GPU is currently held by VFIO for VM passthrough, the host kernel can't create /dev/dri/* or /dev/nvidia* nodes for it. The script offers to run Switch GPU Mode which undoes the VFIO binding; you'll likely need a reboot before re-running Add GPU to LXC.
  • Already configured. If the container already has every dev node for the selected GPU, the script says so and exits cleanly. If it's partially configured, it continues with only the missing pieces.
Step 5

Apply the LXC config changes

Stops the container if running and edits /etc/pve/lxc/<ctid>.conf. Numbered dev<N> entries carry the host video or render GID. Existing lxc.mount.entry bind lines for /dev/dri are replaced by dev: entries; inspect the resulting configuration and permissions.

Example after Intel + NVIDIA on the same container:

# in /etc/pve/lxc/<ctid>.conf
dev0: /dev/dri/card0,gid=44
dev1: /dev/dri/renderD128,gid=104
dev2: /dev/nvidia0,gid=44
dev3: /dev/nvidiactl,gid=44
dev4: /dev/nvidia-uvm,gid=44
dev5: /dev/nvidia-uvm-tools,gid=44
dev6: /dev/nvidia-modeset,gid=44
Step 6

Start the container and install drivers inside

Once the config is written, the script starts the container, waits up to ~30 seconds for pct exec to respond, and then detects the container's distro from /etc/os-release. Based on that, it installs the right userspace packages.

DistroIntel / AMDNVIDIA
Alpineapk add mesa-va-gallium intel-media-driver libva-utilsapk add nvidia-utils
Arch / Manjaropacman -Sy intel-media-driver mesa libva-utilspacman -Sy nvidia-utils
Debian / Ubuntu / othersapt-get install va-driver-all intel-opencl-icd vainfoextract host .run → pct push → run with --no-kernel-modules --no-dkms

Why the NVIDIA .run dance on Debian

Repository packages may not match the host driver. Container libraries must match the loaded host module for NVML tools such as nvidia-smi. The Debian/glibc path uses the cached host-version .run installer, extracts and packs it on the host, transfers it with pct push and installs with --no-kernel-modules --no-dkms. Alpine and Arch use repository packages, whose versions still need checking.
Step 7

Align GIDs and restore state

For Intel/AMD, reads the host GIDs for video and render, using 44/104 only as fallbacks, then edits /etc/group inside the container to match; NVIDIA-only runs skip this step. Entries such as video:44 and render:104 are examples, not universal IDs. Verify app membership and effective device permissions.

On the normal completion path, a container that was initially stopped is stopped again; one that was running stays running. If startup or installation fails, verify its final state and the log.

Vendor-specific notes

Intel iGPU

Intel media acceleration, including Quick Sync, depends on GPU generation, codecs and app configuration. The script shares whichever of /dev/dri/card0, card1, renderD128 and renderD129 exist; other node numbers are not added. The host must already provide them through its native driver, for example i915.

AMD

AMD uses DRI nodes for Mesa/VA-API. If the host exposes /dev/kfd, the script also shares it. ROCm/OpenCL workloads still require supported hardware and compatible userspace packages; sharing the device does not install a complete ROCm stack.

NVIDIA

Shares available /dev/nvidia* nodes. Driver-version matching remains essential for nvidia-smi. Debian/glibc uses the cached host-version .run; Alpine/Arch use repository packages. If the Debian path finds less than 2048 MiB configured RAM, it offers a temporary increase and later restores it; it also requires at least 1500 MiB of free disk space.

After a host NVIDIA update, check container library versions

Old container libraries can make nvidia-smi report a mismatch. The NVIDIA host installer offers container updates. Re-running Add GPU to LXC may exit when its device entries already exist, so it is not a guaranteed library-refresh command. Check the installed versions and update the appropriate container packages or userspace installer.

Verification

After the script finishes, log into the container and check the GPU is visible:

# Enter the container
pct enter <ctid>

# Intel / AMD — check DRI nodes and VA-API
ls -l /dev/dri/
vainfo

# NVIDIA — check nvidia-smi matches the host version
nvidia-smi
nvidia-smi --query-gpu=driver_version --format=csv,noheader

# Check group alignment
getent group video render

Troubleshooting

nvidia-smi: Failed to initialize NVML: Driver/library version mismatch

Container libraries do not match the loaded host module. Inspect versions and update the container userspace appropriately. The cached .run supports the Debian/glibc path, but Add GPU to LXC can exit early when all device entries already exist.

Permission denied on /dev/dri/renderD128 inside the container

Check the device entry and numeric render group permissions, then whether the app user belongs to render. Where available, add that user to render with usermod -aG render <user>, replacing the placeholder with the actual account. Restart the application session to apply membership; changing privilege mode is not a general permissions fix.

vainfo says: VA-API version 1.xx; failed to initialize

Check device access and the selected VA-API driver. Package names vary by distribution: examples include intel-media-driver for supported newer Intel GPUs, i965-va-driver for supported older ones, and mesa-va-drivers for AMD. The message alone does not prove a missing package.

Install log

Every run writes to /tmp/add_gpu_lxc.log on the host. Include it when asking for help on GitHub.

Related