If you install the WSL environment from the Microsoft Store, you can only install one type of distribution as one environment (I think). 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.
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. Execute
wsl --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.
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.
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