# 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.

Source: https://www.jpkc.com/db/en/cheatsheets/shell-system/wsl/

<!-- PROSE:intro -->
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.
<!-- PROSE:intro:end -->

## Install & Setup

`wsl --install` — Install WSL with the default Linux distribution (Ubuntu).

```bash
wsl --install
```

`wsl --install -d <distro>` — Install a specific Linux distribution.

```bash
wsl --install -d Debian
```

`wsl --list --online` — List available distributions for installation.

```bash
wsl --list --online
```

`wsl --update` — Update the WSL kernel to the latest version.

```bash
wsl --update
```

`wsl --version` — Show WSL version, kernel version, and WSLg version.

```bash
wsl --version
```

`wsl --set-default-version 2` — Set WSL 2 as default for new distributions.

```bash
wsl --set-default-version 2
```

## List & Status

`wsl --list` — List installed distributions.

```bash
wsl --list
```

`wsl --list --verbose` — List distributions with state, WSL version, and default.

```bash
wsl --list --verbose
```

`wsl --list --running` — List only currently running distributions.

```bash
wsl --list --running
```

`wsl --status` — Show WSL configuration and default distribution.

```bash
wsl --status
```

## Start, Stop & Run

`wsl` — Start the default distribution.

```bash
wsl
```

`wsl -d <distro>` — Start a specific distribution.

```bash
wsl -d Debian
```

`wsl -u <user>` — Start as a specific user.

```bash
wsl -u root
```

`wsl -e <command>` — Execute a command in the default distribution.

```bash
wsl -e ls -la /home
```

`wsl -d <distro> -e <command>` — Execute a command in a specific distribution.

```bash
wsl -d Ubuntu -e cat /etc/os-release
```

`wsl --shutdown` — Shut down all running distributions and the WSL VM.

```bash
wsl --shutdown
```

`wsl --terminate <distro>` — Terminate a specific distribution.

```bash
wsl --terminate Ubuntu
```

## Distribution Management

`wsl --set-default <distro>` — Set the default distribution.

```bash
wsl --set-default Debian
```

`wsl --set-version <distro> 2` — Convert a distribution to WSL 2 (or 1).

```bash
wsl --set-version Ubuntu 2
```

`wsl --unregister <distro>` — **Destructive:** Unregister a distribution and delete it along with all its data, irreversibly.

```bash
wsl --unregister Ubuntu
```

## Import & Export

`wsl --export <distro> <file>` — Export a distribution as a .tar archive.

```bash
wsl --export Ubuntu ubuntu-backup.tar
```

`wsl --export <distro> <file> --vhd` — Export as a .vhdx virtual disk.

```bash
wsl --export Ubuntu ubuntu-backup.vhdx --vhd
```

`wsl --import <name> <path> <file>` — Import a distribution from a .tar archive.

```bash
wsl --import MyUbuntu C:\WSL\MyUbuntu ubuntu-backup.tar
```

`wsl --import <name> <path> <file> --vhd` — Import from a .vhdx virtual disk.

```bash
wsl --import MyUbuntu C:\WSL\MyUbuntu ubuntu-backup.vhdx --vhd
```

`wsl --import-in-place <name> <file>` — Register an existing .vhdx as a distribution.

```bash
wsl --import-in-place MyDistro C:\WSL\ext4.vhdx
```

## Configuration Files

`/etc/wsl.conf` — Per-distribution settings (automount, network, user, boot).

```bash
[user]
default=myuser

[boot]
systemd=true
```

`%USERPROFILE%\.wslconfig` — Global WSL 2 settings (memory, CPU, swap, networking).

```bash
[wsl2]
memory=8GB
processors=4
swap=4GB
```

`[boot] systemd=true` — Enable systemd in wsl.conf (WSL 2, Windows 11).

```bash
echo -e '[boot]\nsystemd=true' | sudo tee /etc/wsl.conf
```

`[automount] options = "metadata"` — Enable Linux file permissions on Windows drives.

```bash
[automount]
options = "metadata,uid=1000,gid=1000,umask=022"
```

`[network] generateResolvConf = false` — Use custom DNS instead of auto-generated resolv.conf.

```bash
[network]
generateResolvConf = false
```

## Filesystem & Interop

`/mnt/c/` — Access the Windows C: drive from WSL.

```bash
ls /mnt/c/Users/
```

`\\wsl$\<distro>\` — Access the WSL filesystem from Windows Explorer.

```bash
explorer.exe \\wsl$\Ubuntu\home\user
```

`wslpath '<windows-path>'` — Convert a Windows path to a WSL path.

```bash
wslpath 'C:\Users\me\Documents'
```

`wslpath -w '<linux-path>'` — Convert a WSL path to a Windows path.

```bash
wslpath -w /home/user/project
```

`explorer.exe .` — Open the current WSL directory in Windows Explorer.

```bash
explorer.exe .
```

`cmd.exe /c <command>` — Run a Windows command from within WSL.

```bash
cmd.exe /c 'echo %COMPUTERNAME%'
```

`powershell.exe -c '<command>'` — Run a PowerShell command from within WSL.

```bash
powershell.exe -c 'Get-Process | Select -First 5'
```

## Networking & Disk

`wsl hostname -I` — Show the WSL IP address.

```bash
wsl hostname -I
```

`wsl --mount <disk> --bare` — Attach a physical disk to WSL 2.

```bash
wsl --mount \\.\PHYSICALDRIVE1 --bare
```

`wsl --mount <disk> --partition <n> --type ext4` — Mount a specific partition with a filesystem type.

```bash
wsl --mount \\.\PHYSICALDRIVE1 --partition 1 --type ext4
```

`wsl --unmount <disk>` — Detach a mounted disk from WSL.

```bash
wsl --unmount \\.\PHYSICALDRIVE1
```

<!-- PROSE:outro -->
## 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)](https://learn.microsoft.com/en-us/windows/wsl/) – official guide to installation, WSL 2 and configuration
- [Basic WSL commands](https://learn.microsoft.com/en-us/windows/wsl/basic-commands) – complete reference of all `wsl` commands and options
<!-- PROSE:outro:end -->

## Related Commands

- [wslg](https://www.jpkc.com/db/en/cheatsheets/shell-system/wslg/) – run Linux GUI apps under WSL 2 via WSLg
- [powershell](https://www.jpkc.com/db/en/cheatsheets/shell-system/powershell/) – the Windows shell that drives and interacts with WSL
- [bash](https://www.jpkc.com/db/en/cheatsheets/shell-system/bash/) – the default shell in most WSL distributions

