Confined snaps can’t see the NVIDIA GPU on WSL2 due to NVML not propagated into the sandbox

On WSL2 the nvtop snap prints No GPU to monitor., while the same nvtop installed unconfined (apt) sees the GPU fine on the same machine. Looks like NVML isn’t making it into the sandbox under the WSL2 driver layout, findings below.

Environment

  • snapd 2.75.2, Ubuntu 24.04.4 LTS on WSL2, kernel 6.6.114.1-microsoft-standard-WSL2
  • NVIDIA RTX 3090, GPU passthrough on; host nvidia-smi works and lists the GPU
  • nvtop snap rev 344 (3.3.2)

What I see

  • Snap nvtop: No GPU to monitor. Apt nvtop (unconfined): GPU shows up. Same binary version, same NVML — only confinement differs.
  • WSL2 has no /dev/nvidia* and no nvidia kmod; the GPU is /dev/dxg, and the driver (incl. libnvidia-ml.so.1) lives in /usr/lib/wsl/lib.
  • Inside the sandbox /dev/dxg is present (opengl interface), but /usr/lib/wsl/lib/libnvidia-ml.so.1 is not, and /var/lib/snapd/lib/gl/ is empty.
Commands / output
$ snap run --shell nvtop -c 'ls /usr/lib/wsl/lib/libnvidia-ml.so.1; ls /dev/dxg'
ls: cannot access '/usr/lib/wsl/lib/libnvidia-ml.so.1': No such file or directory
crw-rw-rw- 1 root root 10, 125 /dev/dxg

$ ldconfig -p | grep nvidia-ml          # host resolves it fine
        libnvidia-ml.so.1 (libc6,x86-64) => /usr/lib/wsl/lib/libnvidia-ml.so.1

$ ls /var/lib/snapd/lib/gl/             # empty — no libnvidia-ml*

$ ls /sys/module/nvidia/version         # absent on WSL2
No such file or directory
$ lsmod | grep -E 'nvidia|dxgkrnl'
dxgkrnl ...                             # WSL GPU module; no nvidia.ko

For what it’s worth, strings on snap-confine shows it does carry NVIDIA propagation (libnvidia-ml.so*, bind mounting nvidia driver %s -> %s) but the surrounding probes reference /sys/module/nvidia/version, /usr/lib/nvidia, /dev/nvidia%u — none of which exist under WSL2.

In sc_mount_nvidia_driver (cmd/snap-confine/mount-support-nvidia.c) looks like it returns early when /sys/module/nvidia/version is missing — possibly where propagation bails on WSL2. You’d know better than I do whether that’s the relevant path.

Reproduce

  1. WSL2 (Ubuntu 24.04), working NVIDIA GPU — nvidia-smi lists it.
  2. snap install nvtopnvtopNo GPU to monitor.
  3. apt install nvtop (/usr/bin/nvtop) → GPU shows up.

Workaround

Use the unconfined apt build.

I think the problem should be addressed by the following PR:

@jpm-canonical verified it to work for intel, I hope that nvidia will be the same in that regard. This will be part of snapd 2.77, but once we land it it should be in snapd edge within a day or so. Feel free to subscribe to PR notifications.

1 Like

The PR that is linked, and which has been merged in the meantime, exposes /usr/lib/wsl/lib which contains libnvidia-ml.so if the Windows host has an NVIDIA GPU and drivers. I tested it using nvidia-smi inside a snap, as well as some cuda workloads.