avatarSung Kim

Summary

The web content provides a detailed guide on how to run multiple instances of the same Linux distribution on Windows Subsystem for Linux (WSL) in Windows 10/11, ensuring a fresh and stable development environment.

Abstract

The article offers a step-by-step tutorial for Windows 10/11 users to create and manage multiple instances of the same Linux distribution on the Windows Subsystem for Linux (WSL). It emphasizes the importance of maintaining a clean and stable Linux environment for development purposes, which can be achieved by resetting the Linux distro to its initial state and exporting it to create additional instances. The process involves resetting the Linux distro through Windows Settings, exporting the distro to a TAR file, and then importing this file to install new instances of the distro. The guide also includes configuring the new instances for optimal inter, such as setting up automatic mounting and user preferences through the /etc/wsl.conf file. The article, updated in November 2022, provides up-to-date instructions and acknowledges differences in file system navigation between default and imported WSL instances.

Opinions

  • The author suggests that enthusiasm for new development tools can lead to an unstable Linux environment, which can impact productivity.
  • Running multiple instances of the same Linux distro is presented as a solution to avoid the degradation of the Linux environment due to the installation of various tools and configurations.
  • The author implies that using different Linux distros from Microsoft Store may lead to inconsistencies in tool behavior, hence the need for multiple instances of the same distro.
  • The article conveys that the ability to reset and export Linux distros in WSL provides users with a method to maintain a pristine development environment.
  • The author provides a personal tip to shut down all WSL instances when not in use to manage system resources effectively.

Run Multiple Instances of the Same Linux Distro on WSL

How to Simplify Your Development Environments in Windows 10/11 by using Multiple Instances of the Same Linux Distribution on Windows Subsystem for Linux (WSL).

UPDATED ON NOVEMBER 2022 WITH UP-TO-DATE INSTRUCTIONS.

Running Linux on Windows 10/11 via WSL is great, which allows you to fully utilize all the development and system tools available on Linux. Like everything in life, your enthusiasm for the new tools will catch up to you. Installing different tools and configuring your Linux environment to run these tools will result in an unstable Linux environment that will impact your day-to-day productivity.

You can alleviate the eventual degradation of your Linux environment by installing and running different Linux distros from Microsoft Store (for example, you can run Ubuntu, Ubuntu 18.04 LTS, Ubuntu 20.04 LTS, Ubuntu 22.04 LTS, Kali Linux, and Debian at the same time), but you will find that some tools work differently in different Linux distro/version.

Photo by Markus Spiske on Unsplash

The solution is to run multiple instances of the same Linux Distro/Version on WSL. This article will provide step-by-step instructions on running multiple instances of the same Linux Distribution/Version on WSL.

Step-by-Step Instructions (Windows 11)

1. Reset Linux Distro on WSL

The first step is to create a baseline of your Linux distro/version. This is needed so you can have a fresh start when your Linux environment becomes unstable.

Step 1.1: Open “Settings”

Step 1.2: Click on “Apps”

Step 1.3: Click on “Installed Apps”

Step 1.4: Select Linux Distro Name — e.g., Ubuntu 22.04.1 LTS

Step 1.5: Click on the “Advanced Options” link

Step 1.6: Click on the “Reset” button to reset your Linux Distro (e.g., Ubuntu 22.04.1 LTS) to the initial install state. Please note that everything will be deleted.

Step 1.7: When the reset is completed, start your Linux Distro (e.g., Ubuntu 22.04.1 LTS) then set up your Linux Distro by entering both username and password.

Step 1.8: Run “sudo apt-get update” (for Ubuntu 22.04.1 LTS) to retrieve information about what packages can be installed, including what updates to currently installed packages are available, from Internet sources.

Step 1.9: Run “sudo apt-get upgrade” (for Ubuntu 22.04.1 LTS) to install available upgrades of all packages currently installed on the system from Internet sources.

2. Export Linux Distro on WSL

The second step is to create an export image of your Linux Distro. This image will be used to create multiple instances of the same Linux Distro.

Step 2.1: Open a new command prompt or a new Powershell.

Step 2.2: Run the command

wsl --list

to view a list of Windows Subsystems for Linux Distributions installed on your computer. For example on my computer, it would be “Ubuntu-20.04”.

Step 2.3: Run the command

wsl --export <DistributionName> <FileName>

or

wsl --export Ubuntu-22.04.1 rootfs.tar.gz

to export your Linux distros to a TAR file. This will create a file entitled “rootfs.tar.gz” on your computer. Keep this file safe since you will need this file to create a new instance of the WSL Linux Distro.

Step 2.4: Copy the newly created file named “rootfs.tar.gz” to your desired directory. For example on my computer, I have copied the file to c:\linux directory.

3. Install a New Instance of the Same Linux Distro on WSL

Step 3.1. Open a new command prompt or a new Powershell then run the following command to import exported instance as a new instance of Linux in WSL.

wsl --import DistroName InstallationPath ExportedFileLocation

for example,

wsl --import Ubuntu-22.04.1.02 c:\linux\ubuntu-22.04.1.02 c:\linux\rootfs.tar.gz

I have named DistroName as Ubuntu-22.04.1.02 to specify this is Ubuntu 22.04.1 Instance 2.

For WSL2, the installation process should create “ext4.vhdx” file. Delete copied “rootfs.tar.gz” after the installation is completed.

Step 3.2. Run the newly imported Linux distro.

wsl -d DistroName

for example

wsl -d Ubuntu-22.04.1.02

This should start the new instance of Linux Distro in WSL.

Step 3.3. Configure new Linux distro by creating “/etc/wsl.conf” file.

sudo nano /etc/wsl.conf

then enter the following to wsl.conf file then save the file. This is needed to replicate the default behavior of your default Linux distro instance on WSL where you are logged in as a specified user and mounted to its home directory.

[automount]
enabled=true
root=/
[user]
default=sungkim
[interop]
appendWindowsPath = false
[boot]
systemd=true

Please note that you will have to change your username (e.g., sungkim). For more information on wsl.conf, please refer to this website from Microsoft => https://learn.microsoft.com/en-us/windows/wsl/wsl-config.

Step 3.4. Restart Linux Distro

Exit out of Linux Distro

exit

then from either the command prompt or PowerShell, enter

wsl --shutdown

Close Windows Terminal then restart Windows Terminal. A new WSL instance will just show up in Windows Terminal. In Windows Terminal, click on drop-arrow then select the Linux distro name (e.g., Ubuntu-22.04.1.02) to start your new terminal session.

Please note the following differences between a default WSL instance (e.g., Ubuntu 22.04.1) and the imported WSL instances (e.g., Ubuntu 22.04.1.02):

  • To navigate to a host computer (Windows 10/11)’s file system, change the directory to “cd /c” instead of “cd /mnt/c” where the “c” is the drive name.

Conclusion

I hope this tutorial is helpful for you. One tip I would like to leave you with is that whenever you start a WSL session, it will run in the background. You may want to execute “wsl — shutdown” in Powershell to terminate all running WSL instances.

I hope you have enjoyed this tutorial. If you have any questions or comments, please provide them here.

Linux
Ubuntu
Windows 10
Wsl
Windows 11
Recommended from ReadMedium