Scott Hanselman

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

November 22, '19 Comments [6] 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
* 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
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb
Saturday, November 23, 2019 3:20:07 PM UTC
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.
Rob Cannon
Saturday, November 23, 2019 5:53:50 PM UTC
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
Sunday, November 24, 2019 4:05:57 PM UTC
A great post. Consider adding like button to your posts. I would like to give feedback without typing a comment!
Jan Vratislav
Sunday, November 24, 2019 10:09:19 PM UTC
One thing to note with custom wsl distributions, WSL expects bsdtar to be on the path for export to function.
Monday, November 25, 2019 6:44:43 AM UTC
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.
Monday, November 25, 2019 6:04:31 PM UTC
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.
Chris J. Breisch
Comments are closed.

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