How to mount a WSL2 disk on Linux
Mounting a WSL2 disk
If you used WSL2 and wrote some code, here’s how to get your files back on Linux.
What you're dealing with
WSL2 isn’t the lightweight syscall translation layer that WSL1 used. Instead, it runs a full Linux kernel in a lightweight VM using Microsoft's hypervisor. This means your Linux distro’s files live inside a VHDX disk image, not directly on the Windows filesystem.
This design comes with tradeoffs. Cross-filesystem performance can be slow (you’ll probably hate running Git on repos stored on the Windows side). The VM also adds some startup time and uses more memory. The upside is that since everything lives in a disk image, we can mount that image directly from Linux.
Finding your disk image
WSL2 stores each distro’s filesystem inside a VHDX file here:
%AppData%/Local/Packages/{PACKAGE_NAME}/LocalState/ext4.vhdx
The package names vary by distro but follow predictable patterns:
- Ubuntu:
CanonicalGroupLimited.Ubuntu_79rhkp1fndgsc - Debian:
TheDebianProject.DebianGNULinux_76v4gfsz19hv4 - openSUSE:
46932SUSE.openSUSELeap15-2_022rs2aj13994
If you still have Windows available, you can look this up with PowerShell:
wsl --list --verbose
# Then look in each package folder, or:
Get-ChildItem "$env:LOCALAPPDATA\Packages" | Where-Object Name -like "*Ubuntu*"
The ext4.vhdx bit should be consistent across all distributions.
Prerequisites
You'll need a few tools installed. On most distros:
# Install ntfs-3g and qemu-utils
sudo apt install ntfs-3g qemu-utils # Ubuntu/Debian
sudo dnf install ntfs-3g qemu-img # Fedora
If you want to use the NBD approach (explained below), also run:
sudo modprobe nbd max_part=8
Method 1: convert & mount
You can convert the VHDX disk to a raw image and mount it:
qemu-img convert -f vhdx -O raw /mnt/windows/Users/<user>/AppData/Local/Packages/CanonicalGroupLimited.Ubuntu_79rhkp1fndgsc/LocalState/ext4.vhdx ~/wsl-disk.img
sudo mount -o loop ~/wsl-disk.img /mnt/wsl/
This creates a full copy of the disk, so make sure you have enough free space.
Method 2: direct NBD mount
The Network Block Device (NBD) approach lets you mount the VHDX file directly, without converting it:
qemu-nbd --connect=/dev/nbd0 /mnt/windows/Users/<user>/AppData/Local/Packages/CanonicalGroupLimited.Ubuntu_79rhkp1fndgsc/LocalState/ext4.vhdx
sudo mount /dev/nbd0 /mnt/wsl/
When you're done, clean up:
sudo umount /mnt/wsl/
sudo qemu-nbd --disconnect /dev/nbd0
On NixOS
You can grab the tools in a temporary shell
nix-shell -p ntfs3g util-linux qemu-utils
then use either of the methods above.
Which method?
Use NBD if you want to avoid the disk space overhead, or convert to a raw image if you prefer a simpler setup.
Wait, what about mounting Windows?
This assumes you’ve already mounted your Windows partition. If you run into trouble (I definitely did):
- Mount with explicit filesystem type:
sudo mount -t ntfs3 -o rw /dev/<disk> /win ntfsfixif you run into hibernation issues- Try
-o remove_hiberfilewith yourmounts
- ← Previous
Pinning Emacs in the KDE Launcher - Next →
Why the Liar Is the Helpful One