[LINUX] Install and manage multiple environments of the same distribution on WSL

If you install the WSL environment from the Microsoft Store, you can only install one type of distribution as one environment (I think). image.png However, you may want to easily create, destroy, or erase multiple environments of the same distro, or use them as disposable items. You can easily duplicate the environment from the terminal, so I will write how to do it.

procedure

It is assumed that WSL is included. First, run wsl -l --verbose in the terminal to check the environment you have.

PS C:\Users\user01> wsl -l --verbose
  NAME                      STATE           VERSION
* Ubuntu-20.04              Running         2
  docker-desktop            Running         2
  docker-desktop-data       Running         2

For example, if Ubuntu-20.04 installed from the store is included, it will be output as above. I will try to duplicate this Ubuntu installed with the environment name ʻUbuntu-20.04` for disposable use.

The WSL export feature allows you to output the entire environment as a tar file. Just run wsl --export (WSL environment name you want to export) (output file name).

PS C:\Users\user01\export_distro> wsl --export Ubuntu-20.04 FocalFossa_copy.tar

This will output the original ʻUbuntu-20.04environment as a tar file, so you can get the same environment by importing it with a different environment name. Executewsl --import (environment name registered under WSL) (installation path) (import environment.tar)`.

PS C:\Users\user01\export_distro> wsl --import FocalFossa_copy ..\wsl_manual_install\ FocalFossa_copy.tar

Now the same environment as the original ʻUbuntu-20.04` is duplicated with the specified environment name.

PS C:\Users\user01> wsl -l --verbose
  NAME                      STATE           VERSION
* Ubuntu-20.04              Running         2
  FocalFossa_copy           Stopped         2
  docker-desktop            Running         2
  docker-desktop-data       Running         2

You can start it by typing wsl -d (environment name) from the terminal, or you can start it by selecting it from the environment list that can be displayed from the button on the title bar of Windows Terminal. image.png

PS C:\Users\user01> wsl -l --verbose
  NAME                      STATE           VERSION
* Ubuntu-20.04              Running         2
  FocalFossa_copy           Running         2
  docker-desktop            Running         2
  docker-desktop-data       Running         2

Safely, the same distro is running as another name environment.

The hard disk image file ʻext4.vhdx, which is the substance of the environment, is generated in the installation destination specified at the time of import, but since the contents are mounted under \ wsl $ `, browsing from there with Explorer can do. image.png If you want to delete an environment you no longer need, you can delete it with wsl --unregister (registered name).

It's relatively easy to duplicate, destroy, and dispose of the environment, so feel free to play!

Recommended Posts

Install and manage multiple environments of the same distribution on WSL
Building multiple Python environments on the same system
Install wsl2 and master linux on windows
Install python on WSL
Install the latest version of CMake on Ubuntu 18.04.4 LTS
Install django on python + anaconda and start the server
Check the type and version of your Linux distribution
Install the latest version of Git on your Linux server
Install the JDK on Linux
Install multiple versions of Python
wsl Install PostgreSQL on Ubuntu 18.04
Install Docker on WSL Ubuntu 18.04
(One of the solutions) when pyenv install on macOS causes BUILD FAILED and Python installation fails.
How to handle multiple versions of CUDA in the same environment
[EC2] How to install chrome and the contents of each command
Quickly install OpenCV 2.4 (+ python) on OS X and try the sample
The story of Python and the story of NaN
Install Mecab and mecab-python3 on Ubuntu 14.04
Install and run dropbox on Ubuntu 20.04
Install OpenCV and Chainer on Ubuntu
Install CUDA 8.0 and Chainer on Ubuntu 16.04
Build and install OpenCV on Windows
Test the goodness of fit of the distribution
Install fabric on Ubuntu and try
Install easy_install and pip on windows
I tried to visualize the age group and rate distribution of Atcoder
Install the latest version of Apache httpd 2.4 from source on Cent OS 8
Description and summary of what you need to install Chainer on Mac
Text mining: Probability density distribution on the hypersphere and text clustering in KMeans
Summarize the titles of Hottentori at the end and look at the present on the Web
Plot multiple maps and data at the same time with Python's matplotlib