This content originally appeared on DEV Community and was authored by Camilo Martinez
If the C:
drive is running out of space, we can move our WSL2 file system to another drive in a few steps.
Prerequisites
If we are using an user 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 shutdown WSL to avoid data corruption. Close all WSL terminals that are using it and then run 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 not see progress indicators. This can be take a while depending how much data you have. Maybe it's good idea take a rest.
When finish, we need to to unregister the linux distribution from C:
drive. It will also release the disk space.
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 (equiman
in my case) we need to run this 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 🖖
This content originally appeared on DEV Community and was authored by Camilo Martinez

Camilo Martinez | Sciencx (2021-11-27T00:14:32+00:00) Move WSL File System to another Drive. Retrieved from https://www.scien.cx/2021/11/27/move-wsl-file-system-to-another-drive/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.