How to reuse a VHDX file in WSL 2

make sure the version is at least 2.0 on on Win 11/10

wsl --version

if not update it with wsl –update

shutdown the instance

wsl --shutdown

Import in place

(ad3) PS D:> wsl --import-in-place Ubuntu0 D:\wsl\ubuntu\ext4.vhdx

The operation completed successfully.

Ubuntu0 is the name you give to your distribution

  1. Verify:
wsl -l -v
wsl -d MyDistro

 If that VHDX is still used by another registered distro, don’t point two distros at the same file. Export/unregister the old one first or make a copy.

if you see the following error

(ad3) PS D:> wsl -d Ubuntu0
Failed to attach disk 'D:\wsl\ubuntu\ext4.vhdx' to WSL2: Access is denied.
Error code: Wsl/Service/CreateInstance/MountVhd/HCS/E_ACCESSDENIED

Make sure that permissions on that file are set to a real current user.


Set the default user (imported distros default to root)

For imported distros you won’t have a <distroname>.exe launcher, so set it inside Linux:

  1. Start the distro and create a user if needed:
adduser myuser
usermod -aG sudo myuser
  1. Make that user the default by editing /etc/wsl.conf:
sudo sh -c 'printf "[user]\ndefault=myuser\n" >> /etc/wsl.conf'
  1. Terminate and re-open:
wsl --terminate MyDistro
wsl -d MyDistro

Microsoft’s docs note that imported distros should set the default user via /etc/wsl.conf.


Just want to read files from the VHDX?

You can mount a VHDX into WSL without registering it as a distro:

wsl --mount --vhd "C:\path\to\ext4.vhdx"

Then mount the exposed block device inside your running distro. Microsoft Learn


Handy references

  • WSL basic commands (includes --import-in-place--import --vhd). Microsoft Learn
  • Using /etc/wsl.conf to set default user for imported distros. Microsoft Learn+1
  • Community example of --import-in-placeSuper User