WSL Migration

WSL Migration

After using WSL for a while, it can become bloated as more packages are installed. Since the C drive on my current computer is relatively small, I need to move WSL from its default location.

WSL Location

Run this command in PowerShell to find the WSL virtual machine file. Replace <name> with the name of your WSL distribution, mine is Ubuntu:

(Get-ChildItem -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss | Where-Object { $_.GetValue("DistributionName") -eq '<name>' }).GetValue("BasePath") + "\ext4.vhdx"

Migration

Based on this post by jayesh-vachhani, I confirmed that this method works.

Export Ubuntu

1
2
mkdir D:\backup
wsl --export Ubuntu D:\backup\ubuntu.tar

Unregister Existing WSL

1
wsl --unregister Ubuntu

Import

1
2
mkdir D:\wsl
wsl --import Ubuntu D:\wsl\ D:\backup\ubuntu.tar

WSL migration is complete, and you can now start it!

Change Default User

WSL is now usable, but you may notice that the default login user is root. You need to change it:

1
2
cd C:\Users\<your user>\AppData\Local\Microsoft\WindowsApps
ubuntu config --default-user <ubuntu-username>
Built with Hugo
Theme Stack designed by Jimmy