Skip to content

Instantly share code, notes, and snippets.

@4piu
Last active July 31, 2026 02:03
Show Gist options
  • Select an option

  • Save 4piu/112dacab274649f8a4be6e4bfb06b27f to your computer and use it in GitHub Desktop.

Select an option

Save 4piu/112dacab274649f8a4be6e4bfb06b27f to your computer and use it in GitHub Desktop.
Access Nvidia GPU on host from unprivileged LXC
# NVIDIA GPU passthrough
# These needs to be put before including common.conf ¯\_(ツ)_/¯
lxc.cgroup2.devices.allow = c 195:* rwm
lxc.cgroup2.devices.allow = c 509:* rwm
lxc.cgroup2.devices.allow = c 236:* rwm
lxc.mount.entry = /dev/nvidia0 dev/nvidia0 none bind,optional,create=file
# in case you have another GPU
lxc.mount.entry = /dev/nvidia1 dev/nvidia1 none bind,optional,create=file
lxc.mount.entry = /dev/nvidiactl dev/nvidiactl 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/nvidia-caps dev/nvidia-caps none bind,optional,create=dir
# Distribution configuration
lxc.include = /usr/share/lxc/config/common.conf
lxc.include = /usr/share/lxc/config/userns.conf
lxc.arch = linux64
# Container specific configuration
lxc.idmap = u 0 100000 65536
lxc.idmap = g 0 100000 65536
lxc.rootfs.path = dir:/var/lib/lxc/ubuntu-noble/rootfs
lxc.uts.name = ubuntu-noble
# Network configuration
lxc.net.0.type = veth
lxc.net.0.link = lxcbr0
lxc.net.0.flags = up
lxc.net.0.hwaddr = 10:66:6a:2a:20:0c
@4piu

4piu commented Jul 31, 2026

Copy link
Copy Markdown
Author

Install the driver in lxc by running .run installer file with --no-kernel-modules option. Recommended to match the host driver version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment