Skip to main content
SZCZ

How to mount a WSL2 disk on Linux

Mounting a WSL2 disk

Let's say you tried WSL2 and wrote some code. Here's how you get your data back if you're on Linux proper.

What you're dealing with

WSL2 isn't the simple syscall translation layer that WSL1 was. 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 virtual disk file, not directly on the Windows filesystem.

This design comes with tradeoffs. Cross-filesystem performance is pretty slow (you will hate running Git on repos stored on the Windows side). The VM also adds some startup time and uses more memory. But 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 as a VHDX file here:
%AppData%/Local/Packages/{PACKAGE_NAME}/LocalState/ext4.vhdx

The package names vary by distro but follow predictable patterns:

If you're on Windows you can cheat and 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. 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 copy of the disk, so you'll need enough free space.

Method 2: direct NBD mount

Network Block Device (NBD) lets you mount the VHDX file directly without conversion:

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

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 of conversion, or convert to a raw image if you prefer a simpler mount process.

Wait, what about mounting Windows?

I assumed you'd already mounted your Windows partition. If you're having trouble with that (I know I did):