How to add multiple Linux systems manually in WSL(2)

Introduction

The best way to install WSL is from the Microsoft Store, but I’d like to introduce it because I think there are various situations where you want to change your environment or want to do something else.
The two we’re going to introduce here are Ubuntu and CentOS.

The following information was used as a reference for each.

Installing Ubuntu on WSL via rootfs

CentWSL

Ubuntu

Download rootfs (xxxxxxx-server-cloudimg-amd64-wsl.rootfs.tar.gz).
It’s the one with the name WSL on it.

Ubuntu 16.04 LTS (Xenial)
https://cloud-images.ubuntu.com/xenial/current/

Ubuntu 18.04 LTS (Bionic)
https://cloud-images.ubuntu.com/bionic/current/

Ubuntu 19.10 (Eoan)
https://cloud-images.ubuntu.com/eoan/current/

Ubuntu 20.04 LTS (Focal)
https://cloud-images.ubuntu.com/focal/current/

As an example, let’s add Ubuntu20.04 to WSL.
Download the rootfs you want to add.

Translated with www.DeepL.com/Translator (free version)

C:\WSL\focal-server-cloudimg-amd64-wsl.rootfs.tar.gz

Next, add the folder to be installed.
You don’t have to actually add it.

ubuntu2004-1

Since the image of WSL is usually saved in the following folder, please add a folder appropriately.

C:\Users\[UserName]\AppData\Local\Packages\ubuntu2004-1

Open PowerShell.
Import with the following command.
If you add — version 2, it will be imported by WSL2.

wsl --import <DistributionName> <InstallLocation> <FileName> --version 2

You can add a virtual disk named ext4.vhdx to the folder where you installed it.

You can see that it is importing without any problems.

PS C:\Users\jun> wsl -l -v
NAME STATE VERSION
* Ubuntu-18.04 Stopped 2
CentOS8 Stopped 2
ubuntu2004-1 Stopped 2

Let’s actually launch it.

PS C:\Users\jun> wsl -d ubuntu2004-1Welcome to Ubuntu 20.04 LTS (GNU/Linux 4.19.104-microsoft-standard x86_64)

you are going to add a second Ubuntu as a side note.
Add a folder named ubuntu2004–2 and install it.

wsl --import ubuntu2004-2 C:\Users\jun\AppData\Local\Packages\ubuntu2004-2 C:\WSL\focal-server-cloudimg-amd64-wsl.rootfs.tar.gz --version 2

It has been added.

PS C:\Users\jun> wsl -l -v
NAME STATE VERSION
* Ubuntu-18.04 Stopped 2
ubuntu2004-2 Stopped 2
CentOS8 Stopped 2
ubuntu2004-1 Stopped 2

You can now confirm that you can increase it inexhaustibly.

You can also confirm that it is recognized by Windows Terminal.

(sorry, japanese ui)

How to unsubscribe

wsl --unregister ubuntu2004-1

I think this will make it easier to do a lot of things.

CentOS

There are images of CentOS distributed by the following projects.

Unzip it because it is distributed by Zip.

Import as you would on Ubuntu.

wsl --import CentOS8 C:\Users\jun\AppData\Local\Packages\CentOS8 C:\WSL\CentOS8\rootfs.tar.gz --version 2

You can also confirm that you are registered.

PS C:\Users\jun> wsl -l -v
NAME STATE VERSION
* Ubuntu-18.04 Stopped 2
CentOS8 Running 2

If you want to change your home directory, please refer to the following

conclusion

WSL2 will be released and there will be more opportunities to use it, and there will be more integration with Windows.
For example, Docker is now working, and you’ll be able to back up and deploy your development environment after you’ve built it.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jun Kudo

Jun Kudo

I’m Japanese, Microsoft MVP for Azure. Alibaba Cloud MVP. Cloud Solution Architect. Azure, AWS, GCP, and Alibaba Cloud. https://twitter.com/jkudo