Enabling WSL 2 with Ubuntu on Windows 11: From Prerequisites to GPU‑Accelerated Compute
Enable WSL 2 with Ubuntu on Windows 11, add GPU support, set memory/CPU limits, and troubleshoot common issues in a concise, step‑by‑step guide.
07 Dec 2025, 19:57 UTC

Desired Outcome
Run a fully integrated Ubuntu Linux environment on Windows 11 using WSL 2, with GPU compute support, resource limits, and seamless file‑system interoperability. The goal is a ready‑to‑use container or development stack that behaves like a native Linux VM but shares the host’s hardware and file space.
Prerequisites
- Windows 11 22H2 or newer (build 19045+). Verify with
winverorsysteminfo | findstr /C:Build. - Hardware virtualization enabled in UEFI/BIOS. Look for “Intel VT‑x” or “AMD‑V” and enable it.
- Administrator access on the Windows machine.
- Internet connection to download the Ubuntu image and optional GPU drivers.
- For GPU compute: a compatible NVIDIA/AMD/Intel GPU and the latest Windows driver (matching the WSL kernel driver branch).
Step‑by‑Step Procedure
Enable WSL and Virtual Machine Platform
# Run PowerShell as Administrator wsl --install # This command installs the WSL feature, the Virtual Machine Platform, and downloads Ubuntu by default. # If you prefer a different distro, skip the Ubuntu download and install it later from the Microsoft Store.After the command completes, Windows will prompt you to restart. Do so.
Initial Ubuntu setup
# After reboot, launch Ubuntu from the Start menu. # The first run will create a UNIX user and set a password.Force WSL 2 as the default version (optional but recommended)
wsl --set-default-version 2Update the WSL kernel to the latest stable release
wsl --updateWSL 2 ships a lightweight utility VM that runs a Microsoft‑maintained Linux kernel. Keeping it up‑to‑date ensures kernel features and security patches are current.
Configure resource limits (optional)
Create a
.wslconfigfile in your Windows user profile (%USERPROFILE%) with the following content:[wsl2] memory=8GB # Limits VM RAM to 8 GB processors=4 # Uses up to 4 logical cores localhostForwarding=true [boot] systemd=true # Enable systemd inside UbuntuRestart WSL with
wsl --shutdownand launch Ubuntu again to apply the settings.Enable GPU support inside Ubuntu
sudo apt update # Install the driver that matches your Windows GPU driver branch. # Example for NVIDIA: sudo apt install -y nvidia-driver-535 # For AMD or Intel, replace the package name accordingly.After installation, reboot the WSL instance:
wsl --shutdownthen launch Ubuntu again.Verify GPU passthrough
nvidia-smi # Should display GPU details and driver version.
Verification Checks
- WSL version –
wsl -l -vshould listUbuntuwithVERSION 2. - Kernel version – inside Ubuntu,
uname -rshould return a 5.15+ kernel (the exact version depends on the latest WSL update). - File‑system interop – from Ubuntu, run
ls /mnt/c/Usersto access Windows files; from Windows Explorer, navigate to\\wsl$\Ubuntu\home\youruserto access Linux files. - GPU access –
nvidia-smiorclinfoshould list your GPU and driver information. - Resource limits –
free -handnprocinside Ubuntu should reflect the values set in.wslconfig. - Systemd services –
systemctl list-units --type=service --state=activeshould return active services ifsystemd=trueis enabled.
Recovery & Troubleshooting
- Installation fails or WSL doesn’t start: run
wsl --unregister Ubuntuto remove the distribution, then reinstall from the Microsoft Store or viawsl --install -d Ubuntu. - Kernel not loading or errors on boot: execute
wsl --updateto fetch the latest kernel MSI. If that fails, download the MSI manually from Microsoft’s WSL 2 kernel page and install it. - Virtualization disabled in firmware: reboot into BIOS/UEFI and enable VT‑x/AMD‑V. Some OEMs hide it under “Advanced” or “Security” menus.
- GPU passthrough not working: ensure the Windows driver is on the same release branch as the WSL kernel driver. Mismatched versions cause
nvidia-smi: Driver not founderrors. - File‑system latency high: store project files inside
/home/youruserrather than/mnt/c. WSL’s native ext4 filesystem is faster than the Windows NTFS bridge. - Windows Defender scanning Linux files: add exclusions for
\wsl$paths in Defender settings to reduce latency. - Automatic Windows updates resetting the kernel: pin the kernel by running
wsl --update --no-launchafter each update, or use Group Policy to disable auto‑updates for the WSL kernel.
Engineering Rationale
WSL 2 uses a real Linux kernel compiled by Microsoft, running inside a lightweight Hyper‑V virtual machine. This design delivers near‑native syscall compatibility and significantly better I/O performance than the legacy WSL 1 interpreter. For workloads such as Docker, Kubernetes, or GPU‑accelerated machine‑learning pipelines, WSL 2 offers the performance needed while keeping integration with Windows tools (VS Code, PowerShell, etc.) intact.
WSL 1 remains useful for legacy scenarios where the Windows file‑system bridge is the only requirement, but it cannot provide GPU passthrough or full systemd support. Choosing WSL 2 is therefore the default recommendation for modern development and compute tasks.
Advanced Configuration Tips
- Expose environment variables to Windows: add
export VAR=valueto~/.bashrcand usepowershell.exe -Command "$env:VAR = 'value'"to set them in Windows. - Mount additional drives: create a
/mnt/dmount point by editing/etc/wsl.conf:[automount] root = /mnt options = "metadata,umask=22" ``` - Use Docker Desktop with WSL 2 backend: enable the
Use the WSL 2 based engineoption in Docker settings and install thedocker-desktop-datadistro viawsl --install -d docker-desktop-data. - Hot‑reloading the kernel: after updating the kernel, run
wsl --shutdownand thenwslto start a fresh instance with the new kernel.
Limitations and Practical Checks
- WSL 2 does not support nested virtualization; you cannot run Hyper‑V inside WSL 2. For nested workloads, use a full VM.
- GPU support is currently limited to NVIDIA (via CUDA), AMD (via ROCm), and Intel (via OpenCL) drivers that have been ported to WSL. Verify driver compatibility on the vendor’s WSL support page.
- Automatic Windows updates can overwrite the WSL kernel. Keep a local copy of the MSI and reinstall if needed.
- To confirm that the GPU is being used, run a simple CUDA program or an OpenCL benchmark inside Ubuntu and compare performance to native Windows.
Conclusion
By following the steps above, you can quickly spin up a production‑ready Ubuntu environment on Windows 11, leverage GPU acceleration, and control resource usage. The WSL 2 architecture bridges the gap between Windows and Linux, enabling developers to maintain a single machine for both ecosystems without the overhead of a full virtual machine.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.