WSL — Manage Linux Distributions on Windows
Practical guide to WSL: install, start, back up and configure Linux distributions on Windows – including WSL 2, networking and filesystem access.
The Windows Subsystem for Linux (WSL) lets you run full Linux distributions directly on Windows – no dual boot and no traditional virtual machine. WSL 2 powers this with a real Linux kernel running in a lightweight, tightly integrated VM, so the filesystem, networking and your Windows programs all work together seamlessly. The wsl command is your control center: it installs distributions, starts and stops them, backs them up via export and tunes their resources. This guide walks you through the commands you actually reach for daily.
Install & Setup
wsl --install — Install WSL with the default Linux distribution (Ubuntu).
wsl --installwsl --install -d <distro> — Install a specific Linux distribution.
wsl --install -d Debianwsl --list --online — List available distributions for installation.
wsl --list --onlinewsl --update — Update the WSL kernel to the latest version.
wsl --updatewsl --version — Show WSL version, kernel version, and WSLg version.
wsl --versionwsl --set-default-version 2 — Set WSL 2 as default for new distributions.
wsl --set-default-version 2List & Status
wsl --list — List installed distributions.
wsl --listwsl --list --verbose — List distributions with state, WSL version, and default.
wsl --list --verbosewsl --list --running — List only currently running distributions.
wsl --list --runningwsl --status — Show WSL configuration and default distribution.
wsl --statusStart, Stop & Run
wsl — Start the default distribution.
wslwsl -d <distro> — Start a specific distribution.
wsl -d Debianwsl -u <user> — Start as a specific user.
wsl -u rootwsl -e <command> — Execute a command in the default distribution.
wsl -e ls -la /homewsl -d <distro> -e <command> — Execute a command in a specific distribution.
wsl -d Ubuntu -e cat /etc/os-releasewsl --shutdown — Shut down all running distributions and the WSL VM.
wsl --shutdownwsl --terminate <distro> — Terminate a specific distribution.
wsl --terminate UbuntuDistribution Management
wsl --set-default <distro> — Set the default distribution.
wsl --set-default Debianwsl --set-version <distro> 2 — Convert a distribution to WSL 2 (or 1).
wsl --set-version Ubuntu 2wsl --unregister <distro> — Destructive: Unregister a distribution and delete it along with all its data, irreversibly.
wsl --unregister UbuntuImport & Export
wsl --export <distro> <file> — Export a distribution as a .tar archive.
wsl --export Ubuntu ubuntu-backup.tarwsl --export <distro> <file> --vhd — Export as a .vhdx virtual disk.
wsl --export Ubuntu ubuntu-backup.vhdx --vhdwsl --import <name> <path> <file> — Import a distribution from a .tar archive.
wsl --import MyUbuntu C:\WSL\MyUbuntu ubuntu-backup.tarwsl --import <name> <path> <file> --vhd — Import from a .vhdx virtual disk.
wsl --import MyUbuntu C:\WSL\MyUbuntu ubuntu-backup.vhdx --vhdwsl --import-in-place <name> <file> — Register an existing .vhdx as a distribution.
wsl --import-in-place MyDistro C:\WSL\ext4.vhdxConfiguration Files
/etc/wsl.conf — Per-distribution settings (automount, network, user, boot).
[user]
default=myuser
[boot]
systemd=true%USERPROFILE%\.wslconfig — Global WSL 2 settings (memory, CPU, swap, networking).
[wsl2]
memory=8GB
processors=4
swap=4GB[boot] systemd=true — Enable systemd in wsl.conf (WSL 2, Windows 11).
echo -e '[boot]\nsystemd=true' | sudo tee /etc/wsl.conf[automount] options = "metadata" — Enable Linux file permissions on Windows drives.
[automount]
options = "metadata,uid=1000,gid=1000,umask=022"[network] generateResolvConf = false — Use custom DNS instead of auto-generated resolv.conf.
[network]
generateResolvConf = falseFilesystem & Interop
/mnt/c/ — Access the Windows C: drive from WSL.
ls /mnt/c/Users/\\wsl$\<distro>\ — Access the WSL filesystem from Windows Explorer.
explorer.exe \\wsl$\Ubuntu\home\userwslpath '<windows-path>' — Convert a Windows path to a WSL path.
wslpath 'C:\Users\me\Documents'wslpath -w '<linux-path>' — Convert a WSL path to a Windows path.
wslpath -w /home/user/projectexplorer.exe . — Open the current WSL directory in Windows Explorer.
explorer.exe .cmd.exe /c <command> — Run a Windows command from within WSL.
cmd.exe /c 'echo %COMPUTERNAME%'powershell.exe -c '<command>' — Run a PowerShell command from within WSL.
powershell.exe -c 'Get-Process | Select -First 5'Networking & Disk
wsl hostname -I — Show the WSL IP address.
wsl hostname -Iwsl --mount <disk> --bare — Attach a physical disk to WSL 2.
wsl --mount \\.\PHYSICALDRIVE1 --barewsl --mount <disk> --partition <n> --type ext4 — Mount a specific partition with a filesystem type.
wsl --mount \\.\PHYSICALDRIVE1 --partition 1 --type ext4wsl --unmount <disk> — Detach a mounted disk from WSL.
wsl --unmount \\.\PHYSICALDRIVE1 Conclusion
WSL makes Linux on Windows genuinely practical: a handful of wsl commands install, start and back up distributions, while WSL 2 delivers near-native performance thanks to its real kernel and lightweight VM. For everyday work you rarely need more than wsl --install, wsl -l -v, wsl -d <distro> and wsl --shutdown. Treat wsl --unregister <distro> with care, though: it deletes the distribution and all its data irreversibly – back it up first with wsl --export, and move it to another machine via wsl --import when needed. Finer details like memory limits, systemd or DNS are controlled centrally through .wslconfig and wsl.conf.
Further Reading
- WSL documentation (Microsoft Learn) – official guide to installation, WSL 2 and configuration
- Basic WSL commands – complete reference of all
wslcommands and options
Related Commands
- wslg – run Linux GUI apps under WSL 2 via WSLg
- powershell – the Windows shell that drives and interacts with WSL
- bash – the default shell in most WSL distributions