Scott Hanselman

Easily move WSL distributions between Windows 10 machines with import and export!

November 22, 2019 Comment on this post [22] Posted in Linux | Win10
Sponsored By

My colleague Tara and I were working on prepping a system for Azure IoT development and were using WSL2 on our respective machines. The scripts we were running were long-running and tedious and by the time they were done we basically had a totally customized perfect distro.

Rather than sharing our scripts and having folks run them for hours, we instead decided to export the distro and import it on n number of machines. That way Tara could set up the distro perfectly and then give it to me.

For example, when using PowerShell I can do this:

C:\Users\Scott\Desktop> wsl --export PerfectWSLDistro ./PerfectWSLDistro.tar

Then I can share the resulting tar and give it to a friend and they can do this! (Note that I'm using ~ which is your home directory from PowerShell. If you're using cmd.exe you'll want to include the full path like c:\users\scott\Appdata\Local\PerfectDistro)

mkdir ~/AppData/Local/PerfectDistro
wsl --import PerfectDistro ~/AppData/Local/PerfectDistro ./PerfectWSLDistro.tar --version 2

You can list our your WSL distros like this:

C:\Users\Scott\Desktop> wsl --list -v
NAME STATE VERSION
* Ubuntu-18.04 Stopped 2
WLinux Stopped 2
Debian Stopped 1
PerfectDistro Stopped 2

It's surprisingly easy! Also, make sure you have the latest version of the Windows Terminal (and if you've got an old version and haven't deleted your profile.json, it's time to start fresh) it will automatically detect your WSL distros and make menu items for them!

Also be sure to check out my YouTube video on developing with WSL2!


Sponsor: Like C#? We do too! That’s why we've developed a fast, smart, cross-platform .NET IDE which gives you even more coding power. Clever code analysis, rich code completion, instant search and navigation, an advanced debugger... With JetBrains Rider, everything you need is at your fingertips. Code C# at the speed of thought on Linux, Mac, or Windows. Try JetBrains Rider today!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Hosting By
Hosted in an Azure App Service
November 23, 2019 15:20
What is really cool about --import, is that you can use Docker to build a distribution and import that. I haven't been able to figure out how to create a distribution that will allow you to set your userid AFTER you import. That would allow me to create a standard distribution at work that includes all of our tooling. I think I need to create an issue at the WSL github project to enable this scenario, but I am still trying a few things.

https://radu-matei.com/blog/wsl-versioned-filesystem-docker/
November 23, 2019 17:53
Thumbs up! Hugely informative blog. Got some helpful pointers which I will apply in real-life situations. Thanks a lot for uploading this one. If you are Searching for
November 24, 2019 16:05
A great post. Consider adding like button to your posts. I would like to give feedback without typing a comment!
November 24, 2019 22:09
One thing to note with custom wsl distributions, WSL expects bsdtar to be on the path for export to function.
November 25, 2019 6:44
I'm having problems exporting - like this:
C:\Users\Phil\Documents> wsl --export Ubuntu ./WSL2UbuntuEoan.tar
The process cannot access the file because it is being used by another process.

I thought running wsl --shutdown Ubuntu first might help, but no dice. Any advice would be welcomed.
November 25, 2019 18:04
Seems like I use this to make a copy of a distro on my own machine? I was struggling a little bit last week because I wanted a WSL and WSL2 Ubuntu distro on my machine. I eventually figured it out by adding an Ubuntu 16.04 distro, upgrading it, and then updating my existing 18.04 distro to WSL2.

But that's a bit hacky. If I could use your way, and then update one of the two distros to WSL2, I think I'd like that better.
October 13, 2020 8:33
Every weekend i used to visit this web site, because i wish for enjoyment, for
the reason that this this web site conations truly
nice funny data too.
October 25, 2020 22:38
Right away I am going away to do my breakfast, when having
my breakfast coming yet again to read further news.
October 26, 2020 5:39
Great post. I was checking continuously this blog and I'm impressed!

Extremely helpful info specifically the last part :) I care for such
info a lot. I was seeking this certain info for a long time.
Thank you and best of luck.
October 26, 2020 23:26
Pretty great post. I simply stumbled upon your weblog and wanted to
mention that I have really enjoyed browsing your weblog posts.
After all I'll be subscribing on your feed and I am hoping you write
once more soon!
October 27, 2020 5:18
I'm very pleased to discover this page. I want to to thank
you for ones time due to this fantastic read!! I definitely loved
every little bit of it and i also have you book marked to look at new stuff on your blog.
October 27, 2020 9:03
Hi, i think that i saw you visited my web site so i came to “return the favor”.I'm trying to find things to enhance my site!I suppose its ok to use a few of
your ideas!!
October 30, 2020 16:42
Today, I went to the beach with my kids. I found a sea shell and gave it to my 4
year old daughter and said "You can hear the ocean if you put this to your ear." She placed the shell to her ear
and screamed. There was a hermit crab inside and it pinched her ear.

She never wants to go back! LoL I know this is totally off topic but I had to tell someone!
October 30, 2020 17:12
best online loans instant approval
cash advance online
online payday loans no credit check
cash advance america near me now
no credit check payday loans instant approval
November 01, 2020 2:50
What's up, all is going nicely here and ofcourse every one is
sharing information, that's genuinely excellent, keep
up writing.
November 01, 2020 22:19
An outstanding share! I have just forwarded
this onto a co-worker who has been conducting a
little homework on this. And he in fact bought me lunch because I stumbled upon it for him...

lol. So allow me to reword this.... Thanks for the meal!!
But yeah, thanks for spending time to discuss this subject here on your web page.
November 02, 2020 22:32
Very great post. I just stumbled upon your weblog and wanted to mention that I've truly loved surfing around your blog posts.
In any case I'll be subscribing to your rss feed and I am hoping you write once more soon!
November 03, 2020 5:56
Eu sou realmente apreciando o design e o layout
de seu site. É um muito fácil sobre os olhos, que o torna muito mais agradável
para eu vir aqui e visitar mais vezes. Você contratou para fora um designer para criar seu
tema? Excepcional !
November 03, 2020 6:02
If some one desires to be updated with most recent technologies then he must be
pay a visit this web page and be up to date everyday.
November 04, 2020 5:22
Do you mind if I quote a couple of your articles as long
as I provide credit and sources back to your webpage? My blog is in the very same niche as yours and
my users would certainly benefit from some of the information you provide
here. Please let me know if this ok with you.
Thank you!
November 04, 2020 14:53
Hello There. I found your blog the usage of msn. This is a really smartly written article.

I will be sure to bookmark it and return to learn extra
of your helpful information. Thanks for the post. I'llcertainly return.
November 05, 2020 6:24
Pretty section of content. I just stumbled upon your site and in accession capital to assert that I acquire actually enjoyed account your blog posts.
Anyway I'll be subscribing to your feeds and even I achievement you access
consistently quickly.

Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.