Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
November 27, 2021 12:14 am GMT

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):

who am I

Also we need to know the distro name and WSL version, running the wsl --list --verbose command on PowerShell (Windows Side):

WSL list

Knowing the username: equiman, the linux distribution: Ubuntu, and confirm that we are using the WSL 2 version, we are ready to...

moving day

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.

waiting

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

Buy me a coffee


Original Link: https://dev.to/equiman/move-wsl-file-system-to-another-drive-2a3d

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To