Skip to content

Instantly share code, notes, and snippets.

@4piu
Created June 26, 2026 21:17
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
# id mapping
lxc.idmap = u 0 100000 65536
lxc.idmap = g 0 100000 65536
# --- NVIDIA GPU Passthrough Configuration ---
# Allow cgroup access to the devices
# (195 handles nvidiactl/nvidia0, 509 handles nvidia-uvm for CUDA)
lxc.cgroup2.devices.allow = c 195:* rwm
lxc.cgroup2.devices.allow = c 509:* rwm
# Bind mount the required hardware nodes
# Populate the device nodes inside the container cleanly at startup
lxc.hook.pre-start = sh -c "mknod -m 666 ${LXC_ROOTFS_MOUNT}/dev/nvidia0 c 195 0"
lxc.hook.pre-start = sh -c "mknod -m 666 ${LXC_ROOTFS_MOUNT}/dev/nvidia1 c 195 1"
lxc.hook.pre-start = sh -c "mknod -m 666 ${LXC_ROOTFS_MOUNT}/dev/nvidiactl c 195 255"
lxc.hook.pre-start = sh -c "mknod -m 666 ${LXC_ROOTFS_MOUNT}/dev/nvidia-uvm c 509 0"
lxc.hook.pre-start = sh -c "mknod -m 666 ${LXC_ROOTFS_MOUNT}/dev/nvidia-uvm-tools c 509 1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment