Move WSL2 file system to another drive
As opposed to in WSL1, official docs for WSL2 state clearly that I should place files I access frequently from Linux under the Linux file system. However, I have not found any docs on settings for where inside the Windows file system the Linux file system is placed.
Of course, the default location (somewhere under %LOCALAPPDATA%
) is suboptimal if you - like me - have your machine configured to have a minimal C:\
drive and a much larger D:\
- I would much rather place the Linux file system there, to make use of all that space.
Can I somehow control where my Linux file system is placed?
(I don’t have WSL 2 to try.)
WSL supports exporting and importing distributions, like this:
wsl --export Debian C:\temp\Debian.tar
wsl --import MovedDebian C:\WSL\Debian C:\temp\Debian.tar --version 2
Note how I can specify a parameter called InstallLocation
(C:\WSL\Debian
). Keep in mind that in my example, the “Debian” distribution still exists, so I select a different name when importing. You can use the wsl
utility to manage your WSL environments.
If you want to move WSL2 Linux distro(Ubuntu) from C: drive D: below are the steps.
Export Ubuntu
- mkdir D:\backup
- wsl --export Ubuntu D:\backup\ubuntu.tar
Unregister the same distribution to remove it from the C: drive:
- wsl --unregister Ubuntu
Import Ubuntu
- mkdir D:\wsl
- wsl --import Ubuntu D:\wsl\ D:\backup\ubuntu.tar
By default Ubuntu will use root as the default user, to switch back to previous user
Go to the Ubuntu App Folder run command to set default user
- cd %userprofile%\AppData\Local\Microsoft\WindowsApps
- ubuntu config --default-user <username>