Move WSL File System to another Drive
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:\backupwsl --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:\WSLwsl --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\WindowsAppsubuntu config --default-user equiman
Ensure replacing
equiman
with yours.
Restart WSL running wsl
command and it's done.
Thats All Folks!
Happy Coding
Original Link: https://dev.to/equiman/move-wsl-file-system-to-another-drive-2a3d
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To