I have installed WSL2 and deployed two machines on it:
- CentOS
- Ubuntu-20.04
It is possible to run multiple instances of the Ubuntu-20.04 instance on my win10 machine?
I have installed WSL2 and deployed two machines on it:
It is possible to run multiple instances of the Ubuntu-20.04 instance on my win10 machine?
Yes, entirely possible. Here are my recommended steps. In PowerShell (you could use cmd also):
Create a directory somewhere convenient where you want to work with your WSL images. Of course, I name mine WSL
. This does not have to be on your C:\ drive.
Create two subdirectories, images
and instances
. Again, the names are really up to you.
wsl -l -v
just to confirm your current distribution names.
Back up your existing 20.04 distro using something like wsl --export Ubuntu images\2021-02-05_Ubuntu20.04_snapshot.tar
(assuming your distribution is named "Ubuntu", of course).
Create a new instance using that snapshot using something like wsl --import Ubuntu20.04_clone instances\Ubuntu20.04_clone images\2021-02-05_Ubuntu20.04_snapshot.tar --version 2
. You should see an ext4.vhdx
file in your instances\Ubuntu20.04_clone
directory when it is done. The --version
is optional, but shows that you can create WSL1 and WSL2 instances side-by-side if needed. (For instance, WSL1 is much faster if you need to access the NTFS filesystem.)
Launch that instance using wsl ~ -d Ubuntu20.04_clone
. Or restart Windows Terminal (assuming you are using it) and the new instance should be detected automatically.
The new instance will launch as root by default. You will need to set your username by creating a /etc/wsl.conf
with the following:
[user]
default=me
... of course, substituting your username.
Exit, terminate (via wsl --terminate Ubuntu20.04_clone
), and restart that distribution, and confirm that your environment is operating as you'd expect.
Now that you have confirmed your new instance operates correctly, the following steps are optional, but recommended. (For an alternative method, see u/Zoredache's comments (plural) in this Reddit thread).
"Reset" the old image to a clean state by wsl --unregister <distroname>
of the original distribution.
Re-run the "App" (technically it's an "App Execution Alias") from the Windows Start Menu with Start->Run and type Ubuntu. This will re-run the configuration steps and create your default user/password/etc. (Thanks @JackoBongo for the suggestion in the comments for this).
For convenience, I recommend going ahead and adding the /etc/wsl.conf
as described above to this instance. That will keep you from having to do it each time you add or replace an instance. Note: Don't do this if you plan to distribute this image to other users; just if you are doing this for yourself.
Back up this "clean copy" using the wsl --export
command as above, to something like 2021-02-05_Ubuntu20.04_default.tar
. This "clean" version can now be your starting point for a wsl --import
if you want to spin up a new Ubuntu 20.04 to test something out without worrying that your apps/customizations from your normal working environment get in the way.
Since you are already running multiple distributions (CentOS and Ubuntu), then I'm guessing you are using something like Windows Terminal already. But if you launch Ubuntu through the start menu with the "Ubuntu" entry, then you will probably want to copy your cloned vhdx
file back over the newly installed clean version. You'll find the "default" version in %userprofile%\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc
(or something similar).
=
in /etc/wsl.conf
–
Iphagenia wsl --unregister Ubuntu
) and launch it again from the start menu. A console window appears and the initial install process starts. –
Economical tar
file generated by wsl --export
should have everything in that instance. Note that my instructions had you exporting to tgz
(gzipped tar), but it's actually just a plain .tar
that wsl --export
creates. That shouldn't make a difference though, but it will for troubleshooting. Rename it to tar
and check the contents of the tarball to see what's in there. Happy to help you further on this, but probably need to create a new question (on Super User, where it's more on-topic) so we can get the details. Just too much for comments. –
Plate There is also a GUI on GitHub (my project) for managing multiple WSL2 instances. Might save you a little time.
dialog
based to run it in the terminal, but I like the Flutter concept. Also just a reminder that Stack requires you to disclose that you are linking to your own project when you do so. –
Plate © 2022 - 2024 — McMap. All rights reserved.