Change of WSL installation location
I am trying to install the Windows Subsystem for Linux in my PC (Windows 10). I opened a "Command Prompt" window by running it as administrator and ran wsl --install without changing the initial default folder C:\Windows\system32. Thus, WSL is installed in this location by default.
Later, I uninstalled WSL by going to Settings -> Apps & Features -> Windows Subsystem for Linux Update -> Uninstall.
Then, I downloaded and installed WSL Update in C:\users\myaccount. However, when I run WSL from the start menu, it still goes to C:\Windows\system32.
Is there a way to move this default location of WSL installation to C:\users\myaccount. Besides, I have noticed that WSL is still in C:\Windows\system32 folder after I uninstall WSL from Settings -> Apps & Features.
1 Answer
It's important to understand that there are multiple components involved in a WSL installation, and whether you can "move" or change their installation location differs for each of those components:
The
wsl.execommand, which is what you mainly appear to be asking about, is built-in to Windows in recent releases. You didn't (and can't) actually install or uninstall the actualwsl.exethrough any of the Windows Features or Apps & Features settings. It is present when you install Windows.The base Windows Subsystem for Linux ("lxss", to some degree), which is also built into Windows as a "Windows Feature". As a Windows Feature, it can be enabled or disabled, but not, to my knowledge, uninstalled. As you can see in my post here, this takes up very little disk space.
The WSL2 Virtual Machine Platform, which is also a Windows feature.
Like all other Windows features, no, you can't change the location where the files live. Most will be under System32. The fact that you were in that directory when you enabled the feature has nothing to do with it.
I can't recall which of the files in the C:\Windows\System32\lxss directory are there when Windows is installed.
The other components, which are not built-in to Windows, are:
The WSL2 Linux kernel. This is actually what was removed when you uninstalled the "Windows Subsystem for Linux Update". I agree that it is confusingly named.
This official kernel is also installed in a subdirectory with the other WSL binaries, in
C:\Windows\System32\lxss\tools. While you can't change the folder where this kernel is installed, you can move it to another directory if you'd like and create a file in your Windows (not Linux) user profile directory named.wslconfigwith the following contents:[wsl32] kernel="C:\path\to\kernel"You can also compile additional kernels and place them whereever you like, pointing to the one you want to launch in the
.wslconfig.One or more WSL distributions.
When you install a distribution using
wsl --install -d <distro>or from the Microsoft Store, it is installed by default in%USERPROFILE%\AppData\Local\Packages\<PackageName>. These can be "moved" by exporting them and re-importing them.From PowerShell:
mkdir D:\WSL\images # For example mkdir D:\WSL\instances\<newDistroName> cd D:\WSL wsl -l -v # Verify distro name to export wsl --export <distroname> .\images\<distroname>.tar wsl --import <newDistroName> .\instances\<newDistroName> .\images\<distroname>.tar wsl --set-default <newDistroName>You'll also need to set the default username in that copied instance via the
/etc/wsl.conffile as discussed in this answer.It might also be possible to forcibly move the distribution files from your
AppDatafolder to another location and then update the registry corresponding registry location (HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss). However, I have not tested this, nor seen anyone else try it. If you want to give it a shot, make sure you have a backup viawsl --exportabove.