DEV Community

AW A RE
AW A RE

Posted on • Updated on

Installing WSL on another drive in Windows

The only way to do that is to move the linux distrubition you installed on wsl. I installed Ubuntu on windows as wsl and I showed how to move it step by step.

1.Check WSL 2 installations that are already installed in your computer.

wsl --list -v

If the installation you want to move to another drive is still running we have to stop it with following command. In my case, I want to move Ubuntu, so I am terminating Ubuntu.

wsl -t Ubuntu

2.Export to a folder. (Here exporting Ubuntu as ubuntu-ex.tar to D:\wsl\wsl_export)

wsl --export Ubuntu "D:\wsl_export\ubuntu-ex.tar"

3.Unregister previous WSL installation. When you unregister it will remove Ubuntu from the wsl2 list that we saw earlier.

wsl --unregister Ubuntu

4.import your WSL installation to a folder. This step also re-registers the ubuntu.
wsl --import Ubuntu "D:\wsl_import\ubuntu" "D:\wsl_export\ubuntu-ex.tar"

Top comments (17)

Collapse
 
luizvnasc profile image
Guto

life saver

Collapse
 
diwakardayal profile image
Diwakar dayal

thank you!!

Collapse
 
iretex profile image
Iretioluwa Olawuyi

Thanks very much for sharing. This is super helpful!

Collapse
 
kauefraga profile image
Kauê Fraga Rodrigues

Kinda useful! 🔥 Thanks for sharing!!!

Collapse
 
duonghb53 profile image
Maintain

Thank you for sharing

Collapse
 
legion2004 profile image
Milinda Barua

if you get a root user after exporting and if you happen to make a user or had a user already before exporting then go to settings and at the profile of the exported linux distro in the command line tab add the line : wsl.exe -d -u . the part till distro name will be same but pass the -u flag with your username and you will get the previous user that was being used

Collapse
 
ahmed2m profile image
Ahmed Mohamadeen

Thanks!
I'd like to add a reference to some steps mentioned in the default documentation like setting up a default user, because by default --import always starts the image in the root user.
learn.microsoft.com/en-us/windows/...

Collapse
 
kogordev profile image
kogordev

Thank you very much.

Collapse
 
marvinxu profile image
Marvin

Can I set path on initial install?

Collapse
 
zenitk profile image
Zenit Kovačević

That worked, mostly. The WSL2 distro that I imported can't run GUI application anymore for some reason.

Collapse
 
shilohooo profile image
shiloh

Great Post!!!

Collapse
 
georgeleao profile image
George Leão

Thanks my friend!!

Collapse
 
dashdamirli profile image
Asad

Can wsl_export be deleted after running the last command?

Collapse
 
guther profile image
GuTheR

No!! Don't do that!

Collapse
 
wheatfox profile image
wheatfox

THANK YOU!!!!

Collapse
 
alma profile image
Alan Ma

Super solution! Thank you @mefaba
Image description