Cheat Sheets

WSL Cheat Sheet: wsl.exe Commands, .wslconfig and Errors (PDF)

wsl.exe installs, runs, backs up, moves and repairs every Linux distro on Windows 11. This WSL cheat sheet groups its flags by the job at hand and adds the two files people get wrong: .wslconfig on the Windows side and /etc/wsl.conf inside each distro.

Original content from computingforgeeks.com - post 187369

The commands follow Microsoft’s WSL documentation and the WSL 3.0.5 release of November 2026: install and update, wsl --list -v, --set-version, --export and --import, --shutdown, --mount and --manage, then the config keys and the errors behind most broken installs.

WSL cheat sheet: wsl.exe commands by task

Every row below is a flag listed in the wsl --help text of WSL 3.0.5, the stable release Microsoft published on 3 November 2026. Microsoft’s basic commands page still lists only part of that help, so options such as --manage, --cd and --export --format come from the help text itself. Run the install, update, mount and --manage rows from an elevated PowerShell or Windows Terminal tab, because they change Windows features or attach disks; the rest work in a normal tab.

Install, update and uninstall

CommandWhat it does
wsl --installEnable WSL and install the default Ubuntu distro
wsl --install --no-distributionEnable WSL only, add distros later
wsl --install -d DebianInstall a named distro from the online list
wsl --install -d Ubuntu-24.04 --name devInstall a second copy under your own name
wsl --install --from-file C:\images\distro.wslInstall a distro from a local .wsl or tar file
wsl --install -d Debian --no-launchInstall without opening the first-run shell
wsl --updateUpdate WSL to the latest stable release
wsl --update --pre-releaseMove to the latest pre-release build
wsl --versionShow WSL, kernel, WSLg and Windows versions
wsl --statusShow the default distro and default version
wsl --uninstallRemove the WSL package from Windows

List distros and check versions

CommandWhat it does
wsl --list --verboseInstalled distros with state and WSL version (wsl -l -v)
wsl --list --onlineDistros you can install by name (wsl -l -o)
wsl --list --runningOnly distros that are running now
wsl --set-default DebianMake Debian the distro plain wsl opens (-s)
wsl --set-version Debian 2Convert one distro between WSL 1 and WSL 2
wsl --set-default-version 2Version new installs get

Open a shell or run one command

CommandWhat it does
wslOpen the default distro in the current folder
wsl ~Open the default distro in your Linux home
wsl -d DebianOpen a specific distro
wsl -d Debian -u rootOpen it as another user
wsl --cd /var/logStart in a Linux path (a Windows path also works)
wsl -e uname -rRun a program directly, no shell
wsl -- ls -la /etcPass the rest of the line to the default shell
wsl --shell-type loginStart a login shell (standard, login or none)
wsl --systemShell into the hidden system distro (WSLg)

Stop distros and the VM

CommandWhat it does
wsl --terminate DebianStop one distro (-t)
wsl --shutdownStop every distro and the WSL 2 VM
wsl --shutdown --forceStop even while an operation runs (can lose data)

Back up, clone and remove

CommandWhat it does
wsl --export Debian D:\backup\debian.tarExport a distro to a tar file
wsl --export Debian D:\backup\debian.tar.gz --format tar.gzExport compressed (tar, tar.gz, tar.xz, vhd)
wsl --export Debian D:\backup\debian.vhdx --vhdExport the ext4 disk image itself (WSL 2)
wsl --import Debian2 D:\WSL\debian2 D:\backup\debian.tarCreate a new distro from a tar export
wsl --import Debian2 D:\WSL\debian2 D:\backup\debian.vhdx --vhdCreate a distro from a copy of a .vhdx
wsl --import-in-place Debian2 D:\WSL\debian2\ext4.vhdxRegister an existing ext4 .vhdx where it sits
wsl --unregister Debian2Delete the distro and all of its files

Manage disks and storage

CommandWhat it does
wsl --manage Debian --move D:\WSL\debianMove a distro’s disk to another folder
wsl --manage Debian --resize 200GBChange the virtual disk’s maximum size (WSL 2.5+)
wsl --manage Debian --set-sparse trueLet the .vhdx give freed space back to Windows
wsl --manage Debian --set-default-user harrisonChange the user the distro logs in as
wsl --manage Debian --compactCompact the distro’s virtual disk
wsl --mount \\.\PHYSICALDRIVE1 --partition 1Attach a partition of a physical disk (admin)
wsl --mount \\.\PHYSICALDRIVE1 --bareAttach the disk without mounting a filesystem
wsl --mount D:\disks\data.vhdx --vhd --name dataMount a .vhdx at /mnt/wsl/data
wsl --unmount \\.\PHYSICALDRIVE1Detach one disk (no argument detaches all)

Stop the distro with wsl -t Debian before any --manage disk option: WSL refuses --move, --resize and --set-sparse on a running distro. Two rows deserve a warning before you copy them. wsl --unregister asks no question and keeps no recycle bin copy, so export first if there is anything in that distro you want. And the old wslconfig.exe, bash.exe and lxrun commands still appear in forum answers, but Microsoft lists them as deprecated, so use the wsl form from these tables instead.

Which .wslconfig and wsl.conf settings matter?

For most people, two .wslconfig keys matter: memory and processors, because they cap how much of the PC the WSL 2 VM can take. .wslconfig lives at %UserProfile%\.wslconfig and applies to every WSL 2 distro, while /etc/wsl.conf lives inside one distro and only changes that distro. .wslconfig does not exist until you create it. The Ubuntu that wsl --install sets up ships an /etc/wsl.conf that already turns systemd on. A missing or malformed .wslconfig simply means WSL starts with its defaults.

.wslconfig keys ([wsl2] section)

KeyDefault and meaning
memory=8GBRAM cap for the VM; default 50% of Windows RAM
processors=4vCPUs; default all logical processors
swap=4GBSwap size; default 25% of RAM, 0 disables it
swapFile=D:\\wsl\\swap.vhdxSwap file path; default %Temp%\swap.vhdx
networkingMode=mirroredNetwork mode; default nat
dnsTunneling=trueResolve DNS through Windows; default true
firewall=trueApply Windows firewall rules to WSL; default true
autoProxy=trueReuse the Windows proxy settings; default true
localhostForwarding=trueReach WSL ports on localhost (NAT mode); default true
guiApplications=falseTurn WSLg off; default true
nestedVirtualization=trueKVM inside WSL; default true
vmIdleTimeout=60000Milliseconds before an idle VM stops
defaultVhdSize=1099511627776Max disk size for new distros; default 1 TB

Paths in .wslconfig need doubled backslashes, which is why the rows above write D:\\wsl\\swap.vhdx. Two more keys sit under [experimental]: autoMemoryReclaim (disabled, gradual or dropCache, the current default) and sparseVhd=true, which makes newly created disks sparse. A minimal file that caps a laptop at 8 GB and four cores looks like this:

notepad $env:USERPROFILE\.wslconfig

Add the section header and the two keys, then save the file:

[wsl2]
memory=8GB
processors=4

Nothing changes until the VM restarts. Run wsl --shutdown, open the distro again and check the new limit with free -h and nproc.

/etc/wsl.conf keys (per distro)

KeyDefault and meaning
[boot] systemd=trueRun systemd as PID 1; on by default in the Ubuntu that wsl --install adds
[boot] command=service ssh startRun a command as root at distro start
[user] default=harrisonLogin user; needed after wsl --import
[automount] root=/mnt/Where Windows drives appear; default /mnt/
[automount] options=metadataKeep Linux permissions on /mnt/c files
[automount] enabled=falseStop mounting Windows drives; default true
[network] hostname=wsl-ubuntuDistro hostname; default the Windows name
[network] generateResolvConf=falseKeep your own /etc/resolv.conf
[interop] appendWindowsPath=falseDrop Windows folders from Linux $PATH
[interop] enabled=falseBlock running .exe files from Linux
[time] useWindowsTimezone=trueFollow the Windows time zone; default true

The file is plain INI, so the section header goes on its own line above the key. Edit it as root from inside the distro:

sudo vim /etc/wsl.conf

This example turns on systemd, sets the login user and keeps Windows folders out of the Linux $PATH, which speeds up tab completion noticeably on a PC with a long Windows path:

[boot]
systemd=true

[user]
default=harrison

[interop]
appendWindowsPath=false

Microsoft’s docs describe an “8 second rule”: a change is only read once the distro has fully stopped, which takes about 8 seconds after you close every shell. You don’t have to wait. wsl --terminate <distro> applies a wsl.conf change to one distro, and wsl --shutdown applies a .wslconfig change to the whole VM.

How do you check whether a distro runs WSL 1 or WSL 2?

Run wsl -l -v and read the VERSION column: it shows 1 or 2 for every installed distro, next to whether it is Running or Stopped, with an asterisk marking the default. New installs get WSL 2 unless someone ran wsl --set-default-version 1, so a 1 in that column usually means an old distro carried over from an earlier Windows 10 setup.

wsl -l -v

To convert, stop the distro and pass its exact name from that list. The conversion copies the whole filesystem into a new virtual disk, so it takes longer the more you have installed:

wsl --set-version Debian 2

Keep WSL 1 only for a distro that mostly works on files under /mnt/c, where WSL 1 avoids the cross-VM file access cost. Docker, systemd, GPU access, WSLg, --mount and the disk options of --manage (--move, --resize, --set-sparse, --compact) need WSL 2; --manage --set-default-user works on both.

How do you back up, clone or move a WSL distro?

Use wsl --export to back up and wsl --import to restore or clone, and use wsl --manage --move when you only want the disk on another drive. Export writes a tar file by default; --format tar.gz or tar.xz trades export time for a smaller file, and --vhd copies the ext4 disk image as it is. Stop the distro first so nothing writes to it during the export:

wsl --terminate Ubuntu-24.04
wsl --export Ubuntu-24.04 D:\backup\ubuntu-2404.tar.gz --format tar.gz

Importing that file under a new name gives you an independent copy, which is the quickest way to test an upgrade without touching your working distro. The install folder is where WSL creates the new ext4.vhdx:

wsl --import ubuntu-test D:\WSL\ubuntu-test D:\backup\ubuntu-2404.tar.gz

An imported distro logs in as root, because the import knows nothing about the user the first-run setup created. Set [user] default= in its /etc/wsl.conf or run wsl --manage ubuntu-test --set-default-user harrison, then terminate it once. The same export and import pair is how we move Fedora and RHEL images into WSL in our RHEL and Fedora on WSL guide.

When should you use wsl –shutdown instead of –terminate?

Use wsl --shutdown after editing .wslconfig, when the VM holds RAM you want back, or when networking inside WSL is stuck; use wsl --terminate for everything that concerns one distro. Shutdown stops the whole WSL 2 VM, so every open distro shell goes with it. Terminate leaves the VM and the other distros running.

Before either, check what is running so you know what you are about to stop:

wsl --list --running

The VM also stops on its own: vmIdleTimeout defaults to 60000 ms, so about a minute after the last distro stops, Windows gets its memory back without any command. WSL containers with wslc run in their own session VM that .wslconfig does not apply to, and Microsoft’s container settings page stops one with wslc system session terminate rather than a wsl command.

How do you mount a disk or VHD in WSL?

wsl --mount attaches a whole physical disk or a .vhdx to the WSL 2 VM, and it needs an elevated terminal. Microsoft’s mount page lists four limits. Check them before you plan a setup around it:

  • The terminal runs as administrator, or the mount is refused.
  • The disk is not in use by Windows and is not the Windows system disk.
  • The disk is internal: USB sticks, flash drives and SD card readers are not supported.
  • The filesystem is one the WSL kernel supports natively, such as ext4; NTFS goes through /mnt/c-style drvfs instead.

Find the disk path from PowerShell first. The DeviceID column gives the \\.\PHYSICALDRIVE name that --mount expects:

Get-CimInstance -Query "SELECT * from Win32_DiskDrive"

A .vhdx is simpler, and it is also how you read files out of a distro export without importing it. Export with --vhd first, then mount the copy; --name sets the folder under /mnt/wsl/:

wsl --export Ubuntu-24.04 D:\backup\ubuntu-2404.vhdx --vhd
wsl --mount D:\backup\ubuntu-2404.vhdx --vhd --name oldubuntu

Run wsl --unmount with the same path when you are done. Without a path it detaches every mounted disk at once.

Common WSL errors and their fixes

Most WSL failures come down to a missing Windows feature, virtualization switched off in firmware or a damaged virtual disk. The messages below are quoted from Microsoft’s WSL troubleshooting and disk space pages, with what owners added in the Ask Ubuntu and WSL GitHub threads for the same codes.

Error 0x80370102: “The virtual machine could not be started because a required feature is not installed.”

WSL 2 cannot start its VM. Turn on virtualization (Intel VT-x or AMD-V) in the firmware, enable the Virtual Machine Platform feature and reboot. If WSL runs inside a VM, the host has to expose virtualization to it. Also check that the hypervisor is set to start with Windows:

bcdedit /enum | findstr -i hypervisorlaunchtype

If that prints Off, run bcdedit /set hypervisorlaunchtype Auto from an elevated prompt and reboot. When Windows 11 itself runs as a Hyper-V guest, an answer on the Ask Ubuntu thread for 0x80370102 pairs that bcdedit switch on the host with Set-VMProcessor -ExposeVirtualizationExtensions $true on the stopped VM.

WslRegisterDistribution failed with error 0x8007019e

The Windows Subsystem for Linux optional feature is not enabled. Run wsl --install --no-distribution from an elevated terminal, or tick Windows Subsystem for Linux in Turn Windows features on or off, then reboot and install the distro again.

“WSL 2 requires an update to its kernel component”

This shows up as error 0x1bc (0x800701bc) on old inbox installs of WSL, often after wsl --set-default-version 2. Run wsl --update to move to the Store-delivered WSL, which carries its own kernel, and check the result with wsl --version.

“An error occurred mounting the distribution disk, it was mounted read-only as a fallback.”

The distro’s ext4.vhdx has filesystem errors, usually after a forced shutdown or a full host disk. Shut WSL down, attach the disk bare, run e2fsck on it and detach it, then start the distro again:

wsl --shutdown
wsl --mount D:\WSL\debian\ext4.vhdx --vhd --bare
wsl --system -u root lsblk
wsl --system -u root e2fsck -f /dev/sdc
wsl --unmount D:\WSL\debian\ext4.vhdx

Microsoft’s disk space page runs a bare wsl sudo e2fsck, which starts your default distro. If that default is the broken one, WSL tries to attach the same .vhdx twice. That is what a Debian owner hit in WSL issue #10169 (Wsl/Service/CreateInstance/MountVhd/0x80070020, file in use). The block above uses --system -u root, suggested in that thread, which runs e2fsck in the hidden system distro; -u root matters, because without it e2fsck stops at “Permission denied”. It worked for the person who suggested it. It failed for the reporter with the same 0x80070020, and another installed distro fixed their disk: wsl -d Ubuntu -u root e2fsck -f /dev/sdc. Microsoft’s disk space page warns about this too: with a single distro installed, you may need to add a second one for the repair. Use the device that lsblk shows as the newly attached disk in place of /dev/sdc.

Error 0x8000FFFF: unexpected failure

Microsoft’s fix list for this one is generic: run the terminal as administrator, then wsl --update and wsl --shutdown, and repair Windows with sfc /scannow and DISM /Online /Cleanup-Image /RestoreHealth if it persists. Collect wsl --version and wsl -l -v before you open an issue, since the WSL issue template asks for both.

WSL health checklist

Run through these on a new PC or after a big Windows update; each one takes a single command from the tables above, and together they catch most of the problems in the error section before they bite:

  1. wsl --version reports the current stable WSL release.
  2. wsl -l -v shows VERSION 2 for every distro you use daily.
  3. .wslconfig caps memory on a PC with 16 GB of RAM or less.
  4. Imported distros log in as your user, not root.
  5. Every distro you care about has a recent wsl --export file.

For the Windows side of the same desk, our PowerShell cheat sheet, the CMD commands cheat sheet and the wslc cheat sheet cover the commands around WSL, and the full flag list lives in Microsoft’s basic commands for WSL page.

Keep reading

Claude Code Cheat Sheet: Commands, Shortcuts and Flags (PDF) AI Claude Code Cheat Sheet: Commands, Shortcuts and Flags (PDF) OpenAI Codex CLI Cheat Sheet: Shortcuts, Commands, Flags (PDF) AI OpenAI Codex CLI Cheat Sheet: Shortcuts, Commands, Flags (PDF) Linux and DevOps Cheat Sheets (Free PDF Pack) Cheat Sheets Linux and DevOps Cheat Sheets (Free PDF Pack) Install Grok Build on Windows 11 (Formerly Cursor) AI Install Grok Build on Windows 11 (Formerly Cursor) netsh Commands Cheat Sheet: Wi-Fi, Firewall, Port Proxy (PDF) Cheat Sheets netsh Commands Cheat Sheet: Wi-Fi, Firewall, Port Proxy (PDF) Run RHEL 10 and Fedora 45 / 44 on WSL in Windows 11 Tips & Tricks Run RHEL 10 and Fedora 45 / 44 on WSL in Windows 11

Leave a Comment

Press ESC to close