How do I… enable GPU passthrough from Proxmox to unprivileged LXC?

Prerequisites

  1. Downloaded driver and installed the driver with kernel modules on the Proxmox host

Push the driver run-file into the LXC

From the Proxmox host shell:

pct push <lxc id> <path/to/source/file> <path/to/target/file>
pct push 100 ./NVIDIA-Linux-x86_64-580.65.06.run ./NVIDIA-Linux-x86_64-580.65.06.run

Enter into the LXC:

pct enter 100

Find the file and make the run-file executable

chmod +x NVIDIA-Linux-x86_64-580.65.06.run

Uninstall any previous drivers

If you already have a driver installed, this can be uninstalled using the uninstall script that was included in the installation:

/usr/bin/nvidia-uninstall

It will complain about not finding the kernel modules, but since this is an LXC these kernel modules are located on the host (Proxmox) and not in the guest (LXC), so this is fine.

Install the driver

Install using the run-file, but skip the kernel modules:

./NVIDIA-Linux-x86_64-580.65.06.run --no-kernel-module

Mount the GPU device into the LXC

external reference: Using an Nvidia GPU with Proxmox LXC

On the Proxmox host, identify the device IDs:

ls -al /dev/nvidia*

It should return something like this:

# ls -al /dev/nvidia*
crw-rw-rw- 1 root root 195,   0 Aug  4 11:19 /dev/nvidia0
crw-rw-rw- 1 root root 195, 255 Aug  4 11:19 /dev/nvidiactl
crw-rw-rw- 1 root root 195, 254 Aug  4 11:19 /dev/nvidia-modeset
crw-rw-rw- 1 root root 234,   0 Aug  5 14:49 /dev/nvidia-uvm
crw-rw-rw- 1 root root 234,   1 Aug  5 14:49 /dev/nvidia-uvm-tools

The device Ids are in columns 5, so 195 and 234 for the devices under /dev/. Add or update these ids into the unprivileged LXC config. Using the nano editor here:

nano /etc/pve/lxc/<lxc id>.conf

Allow access to the device ids:

lxc.cgroup2.devices.allow: c 195:* rw
lxc.cgroup2.devices.allow: c 234:* rw

Then mount the corresponding device paths into the LXC in the same config file:

lxc.mount.entry: /dev/nvidia0 dev/nvidia0 none bind,optional,create=file
lxc.mount.entry: /dev/nvidiactl dev/nvidiactl none bind,optional,create=file
lxc.mount.entry: /dev/nvidia-modeset dev/nvidia-modeset none bind,optional,create=file
lxc.mount.entry: /dev/nvidia-uvm dev/nvidia-uvm none bind,optional,create=file
lxc.mount.entry: /dev/nvidia-uvm-tools dev/nvidia-uvm-tools none bind,optional,create=file
lxc.mount.entry: /dev/nvram dev/nvram none bind,optional,create=file

Save the config, reboot the LXC and verify that the GPU is available by running nvidia-smi

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

To respond on your own website, enter the URL of your response which should contain a link to this post’s permalink URL. Your response will then appear (possibly after moderation) on this page. Want to update or remove your response? Update or delete your post and re-enter your post’s URL again. (Find out more about Webmentions.)