Language: [πͺπΈ] EspaΓ±ol - [πΊπΈ] English
If the C:
drive is running out of space or do you like to have your files in a different disk than your Operating System, we can move our WSL2 file system to another drive in a few steps.
Prerequisites
If we are using a username different than root, we need to know it running the whoami
command (WSL side):
Also we need to know the distro name and WSL version, running the wsl --list --verbose
command on PowerShell (Windows side):
Knowing the username: equiman
, the linux distribution: Ubuntu
, and confirm that we are using the WSL 2
version, we are ready to...
Move
All next steep need to be done on PowerShell (Windows side).
First, we need to close all terminals that are using WSL, and then shut it down to avoid data corruption running the wsl --shutdown
command.
Next we are going to create a backup from our Ubuntu
linux distribution.
mkdir D:\backup
wsl --export Ubuntu D:\backup\ubuntu.tar
Don't worry if you do not see progress indicators. This can take a while depending on how much data you have. Maybe it's a good idea to take a rest.
When finish, we need to to unregister the linux distribution from C:
drive. It will also release the disk space taken by WSL.
β οΈ Beware that everything that was stored on the WSL drive will be lost, and the command won't ask for a confirmation, so make sure you backup everything you need first!
wsl --unregister Ubuntu
And then, import again on our new disk. I'll use D:
disk as an example.
mkdir D:\WSL
wsl --import Ubuntu D:\WSL\ D:\backup\ubuntu.tar
By default Ubuntu will use root
as default user, to switch to our user we need to run these commands.
cd $env:USERPROFILE\AppData\Local\Microsoft\WindowsApps
ubuntu config --default-user equiman
Ensure replacing
equiman
with yours.
Restart WSL running wsl
command and it's done.
Thatβs All Folks!
Happy Coding π
Top comments (4)
Thanks for this.
Note: the 'wsl' command at the end wouldn't work because the default was set to another distribution (if you have any others like docker-desktop). You can specify the distribution with:
or set the default distribution for wsl:
Thank you for this guide! Ubuntu for example will no longer appear in Apps and Features (if installed via Microsoft Store ... "Ubuntu by canonical etc") but that was no matter to me since I got to move it off my dwindling-space C: drive
Beautifully written and works like charm!
Life saver! Clear and simple walkthrough!