Since some time now Microsoft has blessed all Windows 10 users with the (confusingly dubbed) Windows Subsystem for Linux (WSL).
WSL is a nifty application which allows us to get all the good things we appreciate in a Linux environment on Windows 10 too.
When working in WSL a lot, the files which Windows sets aside for WSL will grow increasingly larger. Up to the point where a reasonable user will consider moving these WSL files to a difference location, to make space on the system drive. Here’s how.
The Status Quo
First get a good overview over which WSL distributions are present on your system and identify the one(s) you want to move.
Open a command prompt and get the list of installed WSL distros:
C:> wsl --list -v NAME STATE VERSION * docker-desktop Running 2 docker-desktop-data Running 2 Ubuntu-20.04 Stopped 2
I will assume the distro to move is Ubuntu-20.04
. Please ignore the fact the default distro (marked by an asterisk *) is docker-desktop
on my system.
It’s recommended to log into the WSL distro you want to move and write down your (default) WSL username before proceeding. It will be needed in the last step.
Down to Business
Next shut down WSL:
C:> wsl --shutdown
Continue to “export” the distro you want to move. This can take a long time and there is no progress bar, therefor patience is of the essence. Also note that the path separator will be \
from now on, since this is done in the Windows command prompt.
# Command format is: wsl --export <distro-name> <file-name> C:> wsl --export Ubuntu-20.04 T:\wsl\Ubuntu-20.04.tar
The export command will pack the WSL distro intro a tar archive file.
Now it’s time to delete the existing distro, which is done by “unregistering” it. This is the one and only dangerous step of the whole procedure, where the WSL files are deleted from their current location.
C:> wsl --unregister Ubuntu-20.04
Verify that the distro is gone for good:
C:> wsl --list Windows Subsystem for Linux Distributions: docker-desktop (Default) docker-desktop-data
Navigate to the target destination where WSL should be moved to and “import” the tar archive.
# Command format is: wsl --import <distro-name> <new-location> <tar-archive> C:> wsl --import Ubuntu-20.04 T:\wsl T:\wsl\Ubuntu-20.04.tar
Again your patience will be required as this can take some time. Again you will have to do something more useful than staring at a progress bar, as there is none.
When done, verify that the distro is present again:
C:> wsl --list Windows Subsystem for Linux Distributions: docker-desktop (Default) docker-desktop-data Ubuntu-20.04
Finishing Touches
If needed one of the listed entries can be set as the default distro:
C:> wsl --set-default Ubuntu-20.04 C:> wsl --list -v NAME STATE VERSION * Ubuntu-20.04 Running 2 docker-desktop Running 2 docker-desktop-data Running 2
Finally restore the default username used in the distro, or otherwise root
will be used. The default username is the username you specified when originally installing the WSL distro. Also it’s the username you hopefully wrote down in the beginning as I recommend you to do.
To change the default username call the appropriate config command:
C:> cd %userprofile%\AppData\Local\Microsoft\WindowsApps C:\Users\...\WindowsApps> ubuntu2004.exe config --default-user Bob
Depending on your distro the command may be different, e.g. just ubuntu.exe
or ubuntu18.04.exe
, but I trust you can figure it out. Also if your default username wasn’t Bob … you know … just use the correct one.
Anyway, that’s how to move a WSL installation which has grown to a size too ginormous for the system drive.
References:
Leave a Reply