Diego Barros Araya
All notes

WSL2 Setup on Windows

Guide to setting up and tuning WSL2 on Windows 11 for development: install, .wslconfig resource limits, Windows Terminal/VS Code integration, and GPU passthrough.

Updated · windows, wsl, linux

WSL2 (Windows Subsystem for Linux 2) runs a real Linux kernel inside a Hyper-V VM. You get a Linux dev environment without leaving Windows. Setup is one command. Making it fast takes some tuning.

Setup flow

Enable WSL2 + install default distro
wsl --install

Create Linux user account

Optionally install another distro
wsl --install -d Debian

Configure .wslconfig
(memory, CPU, networkingMode=mirrored)

Enable systemd in /etc/wsl.conf

Install Windows Terminal
+ WSL profile

Install VS Code
Remote - WSL extension

Move projects into the WSL filesystem
(~/projects, not /mnt/c/)

Optional: GPU passthrough
for CUDA/ML workloads

Steps

  1. Enable WSL2 and install a distro. Run wsl --install in an administrator PowerShell. This turns on the WSL and Virtual Machine Platform features, sets WSL 2 as default, and installs Ubuntu. Restart when prompted.
  2. Create your Linux user. On first launch, set a username/password; this account gets sudo automatically and is specific to that distro.
  3. Pick a different distro if you want one. wsl --list --online to see options, wsl --install -d Debian to add one, wsl --set-default <DistroName> to switch the default.
  4. Configure .wslconfig at %USERPROFILE%\.wslconfig to bound VM resources:
    [wsl2]
    memory=24GB
    processors=8
    networkingMode=mirrored
    dnsTunneling=true
    firewall=true
    localhostForwarding=true
    A good rule for memory is host RAM minus 8GB. Apply changes with wsl --shutdown (closing the terminal window is not enough).
  5. Enable systemd in /etc/wsl.conf inside the distro:
    [boot]
    systemd=true
    Docker, Tailscale, and snapd all depend on systemd being active.
  6. Install Windows Terminal (Microsoft Store), it auto-creates a profile per WSL distro.
  7. Install VS Code’s “Remote - WSL” extension so code . from inside Linux opens a fully remote-aware editor window.
  8. Keep project files inside the WSL filesystem (e.g. ~/projects), not under /mnt/c/.... Access them from Windows Explorer via \\wsl$\<DistroName>\home\<User> if needed.
  9. GPU passthrough (optional, for AI workloads): install only the CUDA Toolkit inside WSL (never the Linux GPU driver, which comes from Windows via GPU-PV). Verify with nvidia-smi inside the distro.

Tips

  • networkingMode=mirrored (Windows 11 22H2+) speeds up WSL2 networking from ~3 Mbps to near-native speed. Set it by default.
  • Exclude the WSL VHDX, Docker data, and ~/projects from Windows Defender real-time scanning. Without this, I/O can be 10-50x slower.
  • Use version managers inside WSL (pyenv, fnm) rather than installing Python/Node globally.
  • Mount extra drives via /etc/fstab with Virtio-FS/9p rather than reaching across /mnt/c/.

Common pitfalls

  • Working from /mnt/c/: node_modules, .git, and build artifacts there make git status/npm install/builds 10-50x slower. Move the project into the Linux filesystem.
  • Installing the full nvidia-cuda meta-package instead of cuda-toolkit-13-x, breaks the driver stubs. GPU drivers only come through Windows.
  • Forgetting systemd=true: Docker/Tailscale/snapd silently fail to start.
  • Third-party firewalls/AV (Kaspersky, AVG, Avast, Symantec) have been reported to block WSL networking outright.
  • .wslconfig changes not applying: a plain terminal close doesn’t restart the VM; run wsl --shutdown first.
  • On a Windows 11 build older than 22H2, networkingMode=mirrored causes network isolation failures. Check your build with winver.

Sources