Syntaxfeed

[Demo] Complete Windows 11 & WSL2 Developer Environment Playbook

Ermine5 min read
Dark TypeScript code editor frame in minimal IDE layout

Configure fast Linux filesystems, bounded VM memory, isolated SSH agent forwarding, mirrored networking, and repeatable distro backups on Windows 11.

Setting up a dual-environment workstation on Windows 11 often stalls not because WSL2 is slow, but because files cross the wrong filesystem boundary, virtual machine memory grows unchecked, or credentials get duplicated across profiles. This playbook walks through a clean, reproducible configuration from bare installation through backup automation.

Keep source repositories strictly inside the Linux virtual disk when running Node.js, Rust, Python, or container toolchains from WSL2, and expose only editor sockets and browser ports back to Windows.

1. Choosing the right filesystem boundary

WSL2 runs a lightweight Linux kernel inside a Hyper-V utility VM. When a Linux process reads files under /mnt/c, every file descriptor travels across the Plan 9 (9P) network file server bridging Windows and Linux. For small config reads that bridge is imperceptible; for node_modules, Git index scans, or database build caches, per-file stat latency compounds quickly.

Windows host vs Linux ext4 virtual disk

Store Windows-native applications (Visual Studio solutions, WinUI projects, desktop installers) on NTFS under C:\Projects. Store Linux-first repositories, Docker volumes, and container build contexts inside your Linux home directory (for example ~/src/app). Visual Studio Code, JetBrains IDEs, and Windows File Explorer read Linux paths transparently over \\wsl.localhost\Ubuntu\home\... without moving files onto NTFS.

WorkloadStored on C:\ (9P Bridge)Stored in WSL2 ext4Operational Notes
Monorepo pnpm install & buildSlow metadata lookupsNative Linux inode speedKeep Linux builds inside ~/src
Git status on 20k+ filesCross-VM stat overheadFast native cacheAvoid dual-OS editing on same clone
Static assets & installersNative Windows speedSlightly slower from ExplorerKeep media drops on NTFS

2. Sizing WSL2 memory and processor limits

By default, WSL2 may allocate up to half of total host RAM, which leaves 16 GB laptops tight when browsers, an IDE, and Docker Desktop run together. Create %UserProfile%\.wslconfig on Windows to enforce explicit memory caps, swap size, and automatic page reclamation.

[wsl2]
memory=6GB
processors=4
swap=2GB
autoMemoryReclaim=gradual
dnsTunneling=true
networkingMode=mirrored
firewall=true

[experimental]
sparseVhd=true

After saving .wslconfig, shut down all running Linux distributions cleanly from PowerShell so the updated kernel parameters take effect on next launch:

wsl --shutdown
wsl -l -v
Administrator PowerShell window running diagnostics
Verify clean shutdown and kernel state before benchmarking memory reclamation

Why autoMemoryReclaim and sparseVhd matter

Linux caches file buffers in unused RAM until memory pressure forces eviction. Without autoMemoryReclaim=gradual, memory allocated during a heavy build stays reserved by the VM long after the compiler exits. Enabling sparseVhd=true alongside periodic compaction also stops deleted container layers from permanently inflating ext4.vhdx on your SSD.

3. Bridging SSH keys cleanly without copying secrets

Copying private keys from C:\Users\<you>\.ssh into ~/.ssh inside every WSL distribution weakens key hygiene and creates drift when keys rotate. Instead, enable the Windows OpenSSH Authentication Agent service once, store your passphrased Ed25519 key there, and instruct Git inside WSL2 to invoke Windows ssh.exe.

# Run once in an elevated PowerShell session
Get-Service ssh-agent | Set-Service -StartupType Automatic
Start-Service ssh-agent
ssh-add "$env:USERPROFILE\.ssh\id_ed25519"
ssh-add -l

Inside Ubuntu or Debian on WSL2, configure Git to use the Windows OpenSSH executable cleanly:

git config --global core.sshCommand "ssh.exe"
git config --global credential.helper "/mnt/c/Program\ Files/Git/mingw64/bin/git-credential-manager.exe"
ssh -T git@github.com
  1. Verify ssh-add -l prints your single public key fingerprint on Windows.
  2. Confirm Git inside WSL2 connects without prompting for a copied private key passphrase.
  3. Never set world-readable permissions (chmod 777) on .ssh directories if you also store local config aliases.

4. Networking, DNS resolution, and local ports

Corporate VPN clients and split-tunnel resolvers frequently break /etc/resolv.conf inside traditional NAT-mode WSL2 instances. Enabling networkingMode=mirrored and dnsTunneling=true in .wslconfig aligns WSL2 interface addressing directly with the Windows host routing table.

System performance and latency telemetry dashboard
Monitor loopback latency and memory headroom across local development servers

With mirrored networking active, local dev servers bound inside Linux (localhost:3000, 127.0.0.1:5432) share the host loopback cleanly, and encrypted DNS over HTTPS settings configured on Windows adapters apply without editing custom resolver scripts inside Linux.

# Inspect active Windows DoH servers and listening dev ports
Get-DnsClientDohServerAddress
netstat -ano | Select-String ":3000|:5432"

Firewall rules for LAN testing

When testing responsive layouts from a physical phone on the same Wi-Fi network, remember that mirrored mode routes incoming connections through Windows Defender Firewall. Keep production databases bound to 127.0.0.1, and allow temporary LAN access only on Private network profiles rather than disabling firewall protections globally.

5. Git line endings, tooling, and Windows Defender hygiene

Consistent line endings prevent noisy cross-platform diffs where every file appears modified. Enforce explicit repository rules with .gitattributes alongside a sane Linux/Windows Git configuration:

# ~/.gitconfig inside WSL2
[core]
  autocrlf = input
  filemode = true
  fsmonitor = true

[pull]
  rebase = true
  • Always maintain explicit .gitattributes (* text=auto eol=lf) for shell scripts and frontend configs.
  • Leave real-time Microsoft Defender active across Downloads, browsers, and C:\. If build caches on NTFS slow down Windows-native builds, scope exclusions strictly to specific build output directories rather than excluding whole user folders.

6. Automated distro backup and recovery checklist

Before major Windows feature upgrades or container runtime resets, export a timestamped archive of your configured Linux distribution to secondary storage:

New-Item -ItemType Directory -Force -Path "D:\Backups\WSL" | Out-Null
wsl --shutdown
wsl --export Ubuntu "D:\Backups\WSL\ubuntu-dev-$(Get-Date -Format yyyy-MM-dd).tar"

To restore onto a clean machine later without re-configuring dotfiles or packages:

  1. Create a target install directory such as C:\WSL\Ubuntu.
  2. Run wsl --import Ubuntu C:\WSL\Ubuntu D:\Backups\WSL\ubuntu-dev-YYYY-MM-DD.tar.
  3. Set your default non-root user in /etc/wsl.conf under [user] so interactive shells launch directly into your developer account.

7. Troubleshooting common failure states

High host RAM usage during idle periods

Check host memory consumption via wsl -l -v and Task Manager's VmmemWSL process. If buffers have not drained after heavy Node.js or container runs, verify .wslconfig uses autoMemoryReclaim=gradual (not misspelled) and run wsl --shutdown to verify memory returns immediately.

Stale localhost ports staying bound after crashes

If a crashed dev server leaves port 3000 occupied across Windows and WSL2, list processes inside Linux via ss -tulpn | grep 3000 and terminate only the orphaned PID rather than force-killing the entire VM.

Broken DNS lookups on VPN connect

Inspect cat /etc/resolv.conf inside WSL2 and confirm Windows did not overwrite DNS settings with an unreachable gateway IP. With dnsTunneling=true enabled, WSL2 delegates DNS queries directly through Windows APIs even when VPN split tunnels swap active interfaces mid-session.

Sources & Primary References

Ermine

View all →