Note: I've discovered that there's an earlier version of this question here. I've posted a new answer on that question with information on the wsl --import --vhd
option, which wasn't available at the time I wrote this answer. I'm leaving this one in place, since it did ask a slightly different question (that I answered) as well, but most users should see the updated answer on the earlier question.
Older answer:
A few notes:
According to the Microsoft Doc it is located in
C:\Users\<UserName>\.wslconfig
Well, no, that's not where the distribution is stored for WSL. That's simply one of the WSL configuration files. You can't find it because it doesn't exist (nor is needed) by default. You would only need to create it if you wanted to override one of the default settings.
WSL distributions installed from the Microsoft Store will typically be in a package specific directory under:
%userprofile%\AppData\Local\Packages\
You can get the actual location by running the following in PowerShell:
Get-ChildItem HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss\ |
ForEach-Object {
(Get-ItemProperty $_.PSPATH) | Select-Object DistributionName,BasePath
}
But with that said, you shouldn't access this directory directly.
Instead, use the built-in WSL features to:
- backup the existing distribution and restore it to the new location
- set the default username in the new distribution
- unregister the old distribution
Specifically:
Please don't just copy and paste the commands below without attempting to understand what they are doing. Please run each command separately, so that you can handle any errors that might occur.
First, exit the existing distribution (Debian, in your case).
Then, in PowerShell (as a normal user, not Admin):
wsl -l -v
# Confirm the existing distribution name
# Modify variables below as needed/desired
$WSL_ROOT="D:\WSL"
$WSL_IMAGE_PATH="${WSL_ROOT}\images"
$WSL_OLD_DISTRO_NAME="Debian"
$WSL_NEW_DISTRO_NAME="Debian_WSL2"
$WSL_INSTANCE_PATH="${WSL_ROOT}\instances\${WSL_NEW_DISTRO_NAME}"
mkdir $WSL_IMAGE_PATH
mkdir $WSL_INSTANCE_PATH
# Create a backup/export of the existing Debian in `D:\WSL\images\Debian.backup.tar`
wsl --shutdown
wsl --export $WSL_OLD_DISTRO_NAME "${WSL_IMAGE_PATH}\${WSL_OLD_DISTRO_NAME}.backup.tar"
# Import that backup into the new location/distribution:
wsl --import $WSL_NEW_DISTRO_NAME $WSL_INSTANCE_PATH "${WSL_IMAGE_PATH}\${WSL_OLD_DISTRO_NAME}.backup.tar" --version 2
# Start the new distro:
wsl ~ -d $WSL_NEW_DISTRO_NAME
You next need to set the default username, since WSL doesn't "remember" it for --import
ed distributions. From inside the new Debian distro:
sudo -e /etc/wsl.conf
# Yes, you are already root, but `sudo -e` is just a fairly safe way to invoke the default editor regardless of distribution
Add the following:
[user]
default=<your_normal_username>
Save and exit the editor.
exit
the shell/WSL.
Back in the same PowerShell session (so all the variables are still intact):
wsl --terminate $WSL_NEW_DISTRO_NAME
wsl --set-default $WSL_NEW_DISTRO_NAME
wsl ~
You should now be running as your normal user in the new Debian location.
To confirm, wsl.exe -l -v
should show that the new distro is running, and the old one is not. Additionally, from PowerShell:
Get-ChildItem HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss\ |
ForEach-Object {
(Get-ItemProperty $_.PSPATH) | Select-Object DistributionName,BasePath
}
... will show the installed distributions and their locations.
After confirming that everything is working properly:
Warning: This is a destructive and unrecoverable operation
$WSL_OLD_DISTRO_NAME="Debian"
wsl --unregister $WSL_OLD_DISTRO_NAME
You can also uninstall the Debian app from the Store as well, but I personally recommend keeping it around.