Windows Subsystem for Linux on Windows Server 2022

Windows Subsystem for Linux version 2 (WSL2) is available on Windows Server 2022 and provides a genuine Linux kernel running inside a lightweight Hyper-V utility VM, giving you a near-native Linux environment directly on a Windows Server host. Unlike the original WSL1 which translated Linux system calls to Windows equivalents, WSL2 runs a real Linux kernel (maintained by Microsoft, updated via Windows Update), which means full syscall compatibility, real ext4 filesystem performance, and support for tools like Docker-in-WSL, inotify, and eBPF.

On Windows Server 2022, WSL2 is particularly useful for development teams that need Linux build pipelines, DevOps engineers who want to run bash-based automation on a Windows host, and scenarios where you need Linux containers without a separate Linux VM. This article walks through a complete WSL2 setup on Windows Server 2022, covering feature enablement, distribution installation, configuration tuning, networking, and production considerations.

Enabling WSL2 Prerequisites

WSL2 requires two Windows optional features: the Windows Subsystem for Linux feature itself, and the Virtual Machine Platform feature (which provides the Hyper-V infrastructure WSL2 uses for its lightweight VM). On Windows Server 2022, these are enabled via PowerShell with Enable-WindowsOptionalFeature or DISM. The server does not need the full Hyper-V role installed — Virtual Machine Platform is a separate, lighter component.

Run the following in an elevated PowerShell session:

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux -NoRestart
Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -NoRestart

After running both commands, restart the server:

Restart-Computer -Force

Alternatively, using DISM directly:

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

After the reboot, set WSL2 as the default version. This ensures all subsequently installed distributions use WSL2 rather than WSL1:

wsl --set-default-version 2

Installing the WSL2 Kernel Update Package

On Windows Server 2022, the Linux kernel package for WSL2 may not be present immediately after enabling the feature. Download and install it manually from Microsoft:

Invoke-WebRequest -Uri "https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi" -OutFile wsl_update_x64.msi -UseBasicParsing
Start-Process msiexec.exe -ArgumentList '/i wsl_update_x64.msi /quiet' -Wait

On fully updated Windows Server 2022 (with recent cumulative updates applied), the kernel may already be present. You can check the installed kernel version:

wsl --version

Installing Linux Distributions

The wsl --install command with the -d flag installs a distribution from the Microsoft Store catalog, but on Windows Server 2022 the Store may not be available. In that case, download distribution packages manually. Microsoft publishes appx/tar.gz archives for all major distributions.

Install Ubuntu 22.04 LTS manually on Server 2022:

Invoke-WebRequest -Uri "https://aka.ms/wslubuntu2204" -OutFile Ubuntu2204.appx -UseBasicParsing
Add-AppxPackage Ubuntu2204.appx

If Add-AppxPackage is unavailable (no Store infrastructure), extract and register directly:

Rename-Item Ubuntu2204.appx Ubuntu2204.zip
Expand-Archive Ubuntu2204.zip -DestinationPath C:WSLUbuntu2204
C:WSLUbuntu2204ubuntu2204.exe

The first launch initializes the distribution and prompts for a Linux username and password. After initialization, verify it is running as WSL2:

wsl --list --verbose

Expected output:

  NAME            STATE           VERSION
* Ubuntu-22.04    Running         2

If the version shows 1, convert it:

wsl --set-version Ubuntu-22.04 2

Configuring WSL2 with wsl.conf and .wslconfig

WSL2 has two configuration files with different scopes. /etc/wsl.conf is placed inside the Linux distribution and controls per-distribution settings such as automounting Windows drives, hostname, and interop behavior. C:Users<username>.wslconfig (on the Windows side) controls global WSL2 VM settings including memory, CPU count, and swap allocation.

Create or edit /etc/wsl.conf inside the Ubuntu distribution to configure automount and hostname:

[automount]
enabled = true
root = /mnt/
options = "metadata,umask=22,fmask=11"
mountFsTab = true

[network]
hostname = ws2022-wsl
generateHosts = true
generateResolvConf = true

[interop]
enabled = true
appendWindowsPath = true

[boot]
systemd = true

The systemd = true option enables systemd inside WSL2, allowing you to use systemctl to manage services — available since WSL2 kernel 0.67.6.

On the Windows side, create .wslconfig in the user profile directory to limit VM resource usage (important on a production server where WSL is a secondary tool):

[wsl2]
memory=4GB
processors=2
swap=2GB
swapFile=C:\WSL\wsl-swap.vhdx
localhostForwarding=true
kernelCommandLine=vsyscall=emulate
nestedVirtualization=false

Apply the new configuration by shutting down WSL2:

wsl --shutdown

The next time you launch a WSL2 distribution, the new resource limits take effect.

WSL2 Networking on Windows Server 2022

WSL2 uses a NAT-based virtual network adapter by default. The WSL2 VM gets a private IP address (typically in the 172.x.x.x range) and traffic is NATed through the Windows host. This means the Linux environment can reach the internet through the host’s network adapter, but external machines cannot directly reach services running inside WSL2 without port forwarding.

To expose a port from WSL2 to the network, use netsh interface portproxy on Windows:

# Get the WSL2 IP address
wsl hostname -I

# Set up port forwarding (example: forward port 8080 to WSL2 port 8080)
$wslIP = (wsl hostname -I).Trim()
netsh interface portproxy add v4tov4 listenport=8080 listenaddress=0.0.0.0 connectport=8080 connectaddress=$wslIP

# Also open Windows Firewall
New-NetFirewallRule -DisplayName "WSL2 Port 8080" -Direction Inbound -Protocol TCP -LocalPort 8080 -Action Allow

Since the WSL2 VM IP changes on every restart, automate the portproxy update with a startup script or Task Scheduler job.

Accessing Windows Files from Linux

Windows drives are mounted inside WSL2 at /mnt/c, /mnt/d, etc. You can read and write Windows files directly from Linux commands. For example, to list the contents of C:WindowsSystem32 from inside WSL2:

ls /mnt/c/Windows/System32/ | head -20

When working with files in WSL2, store them in the Linux filesystem (~/projects etc.) rather than /mnt/c for best I/O performance. The DrvFs filesystem used for Windows drive mounts involves a translation layer that is significantly slower than the ext4 virtual disk used for the Linux root filesystem.

Conversely, Windows applications can access WSL2 files through the UNC path \wsl$Ubuntu-22.04 in File Explorer or from PowerShell:

Get-ChildItem "\wsl$Ubuntu-22.04homeusernameprojects"

Using Linux Tools from PowerShell via wsl Command

The wsl command lets you invoke Linux executables directly from PowerShell or cmd.exe without opening a Linux shell interactively. This is powerful for scripting scenarios where you need Linux tools like awk, grep, sed, curl, python3, or custom Linux binaries as part of Windows automation.

# Run a single Linux command
wsl ls -la /home/username

# Use Linux grep to filter Windows file content
Get-Content C:logsapplication.log | wsl grep "ERROR"

# Run a Python script stored in WSL2
wsl python3 ~/scripts/analyze.py

# Execute bash script
wsl bash -c "cd ~/app && ./build.sh"

# Use awk to process output
wsl df -h | wsl awk '{print $1, $5}'

Standard input and output are piped correctly between PowerShell and WSL2 commands, enabling composable pipelines that mix Windows and Linux tools.

Docker Desktop with WSL2 Backend on Server 2022

Docker Desktop for Windows uses WSL2 as its backend when available, running the Docker daemon inside the WSL2 VM rather than in a separate Hyper-V VM. This provides better performance and tighter Linux kernel integration. On Windows Server 2022 with WSL2 enabled, install Docker Desktop and enable the WSL2 backend in its settings.

After installation, integrate specific WSL2 distributions with Docker Desktop from Docker Desktop Settings > Resources > WSL Integration. Once integrated, you can run Docker commands from inside the Ubuntu WSL2 terminal as if Docker were natively installed in Linux.

Production Considerations: Disabling WSL on Production Servers

On production Windows Server 2022 instances that do not require WSL2, the feature should be disabled to reduce the attack surface. WSL2 introduces a Hyper-V utility VM, a Linux kernel, and file system bridges — none of which are needed on a dedicated web server, domain controller, or database server.

Disable WSL on production servers:

Disable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux -NoRestart
Disable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -NoRestart
Restart-Computer -Force

For server hardening via Group Policy in an AD environment, you can also use the policy at Computer Configuration > Administrative Templates > Windows Components > Windows Subsystem for Linux to prevent WSL2 installation and execution across a fleet of servers.