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…


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

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:\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.

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:\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 🖖

Buy me a coffee


This content originally appeared on DEV Community and was authored by Camilo Martinez


Print Share Comment Cite Upload Translate Updates
APA

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/

MLA
" » Move WSL File System to another Drive." Camilo Martinez | Sciencx - Saturday November 27, 2021, https://www.scien.cx/2021/11/27/move-wsl-file-system-to-another-drive/
HARVARD
Camilo Martinez | Sciencx Saturday November 27, 2021 » Move WSL File System to another Drive., viewed ,<https://www.scien.cx/2021/11/27/move-wsl-file-system-to-another-drive/>
VANCOUVER
Camilo Martinez | Sciencx - » Move WSL File System to another Drive. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/11/27/move-wsl-file-system-to-another-drive/
CHICAGO
" » Move WSL File System to another Drive." Camilo Martinez | Sciencx - Accessed . https://www.scien.cx/2021/11/27/move-wsl-file-system-to-another-drive/
IEEE
" » Move WSL File System to another Drive." Camilo Martinez | Sciencx [Online]. Available: https://www.scien.cx/2021/11/27/move-wsl-file-system-to-another-drive/. [Accessed: ]
rf:citation
» Move WSL File System to another Drive | Camilo Martinez | Sciencx | 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.

You must be logged in to translate posts. Please log in or register.