This is a brief guide on how to install Archlinux as a WSL2 distribution and how to set up CUDA afterwards.
As of late, Window's WSL2 offers GPU passthrough from WSL2/Linux to Windows for NVidia graphics cards which allows to run (and develop) CUDA-based applications on the WSL2/Linux-side with almost native performance. Unfortunately, the official guides for the CUDA setup for WSL2/Linux are predominantly Ubuntu-specific. Here's to you, Arch!
- Make sure that your Windows meets the dependencies and that your WSL2 is set up. See these instructions.
Archlinux is not among the default distributions available for WSL2. We'll install it from a tarball instead, a functionality offered natively by the WSL.
- Download the latest release of the root-fs tarball from the Archlinux Gitlab. Pick the base-devel version whose filename at the time of writing is base-devel-20211124.0.39890.tar.xz.
The WSL can work with pure .tar archives or its g-zip compressed counterparts, .tar.gz archives, but it cannot handle .tar.xz archives.
- Generate a .tar archive from the downloaded .tar.xz file by decompressing.
Under Linux this can be done via unxz -c "$your_file.tar.xz" > arch_base-devel.tar
. If you don't have quick access to a Linux machine, install the WSL2 Ubuntu distribution from the Microsoft Store. The Windows filesystem is mounted at /mnt/c/
, whence you can access and decompress the downloaded archive.
We now need to set up a space in the Windows filesystem where all the data for the Archlinux distribution will reside.
- Create a new directory for the Archlinux distribution, e.g
C:\wsl-distributions\archlinux
.
We're now ready to install Archlinux from the tarball.
- In a PowerShell execute
wsl --import archlinux C:\wsl-distributions\archlinux C:\Path-to-your-tar-file\arch_base-devel.tar
.
Once this is finished, your Archlinux distribution is ready to roll. Open a new Windows Terminal and launch a new Archlinux shell. You may now configure the system to your liking. In order to not have to maintain Docker build scripts on Windows and WSL2/Linux, the Docker Desktop Windows application offers WSL2 integration.
- Install the Docker Desktop Windows application and enable the WSL2 engine.
Done. You may want to explore the WSL configuration parameters and adjust your setup. With regards to this guide this step is completely optional and can be postponed.
Disclaimer:
- There's no systemd support for WSL2 yet, so don't install software which depends on it.
- You may be unable to
ping
as a normal user. Runsudo setcap cap_net_raw+p /bin/ping
to fix the issue. See this issue for more information.
Luckily for Archlinux users, the CUDA installation is trivial because the cuda and cuda-tools packages don't explicitly depend on the Linux NVidia drivers, which must not be installed as they would interfere with the WSL2's GPU "paravirtualization".
- In Windows install the latest CUDA-enabled GPU drivers for WSL from the NVidia Developer Page.
- In Archlinux Install the cuda and cuda-tools packages:
pacman -S cuda cuda-tools
.
You should now be ready to write and use CUDA-based applications and software. You can test it by building a simple example from the NVidia CUDA Introduction or run a CUDA-based Docker container from the NVidia WSL User Guide.
Disclaimer:
- There's no WSL2 support for the CUDA profiling tools yet.
- Some old tutorials use
nvidia-docker
, which is obsolete as Docker now natively handles NVidia GPUs. Instead ofnvidia-docker run
simply usedocker run --gpus all
. If you must usenvidia-docker
, which is available from the AUR, and you run into trouble with Docker, try running the Docker daemon on the Linux side and disable Docker Desktop.
Hi @slavistan, while I tried to install
cuda
, the package requiresnvidia-utils-510.60.02-1
, which do contains an extralibcuda.so
and seems like a driver (not sure).Have you tried if that will conflict with the Windows version under
/usr/lib/wsl/lib
?The detailed output of
pacman
is shown below:Thanks if you got any idea.