WSL
Linux environment
Windows Subsystem for Linux
tutorial
ubuntu
Check the required commands
If you run
wsl --help
Now if you scroll down, you will find this line:
This helps us export and then import the same distribution. By doing this, you are effectively duplicating the same distribution, allowing you to run multiple instances of the same Linux environment.
Export Command
The export command is:
wsl --export <Distro> <FileName> [Options]
<Distro>
: The name of the Ubuntu distribution that we want to copy (required).<FileName>
: The location and name that you want to save the new distro with your custom name (required).[Options]
: Optional parameters you can add.
To find the <Distro>
name, run:
wsl -l -v
This lists the installed WSL distributions.
Exporting the Ubuntu Distro
Run the export command based on your requirements:
wsl --export Ubuntu-22.04 E:\wslDistro\Ubuntu-22.04_export.tar
Importing the Ubuntu Distro
The import command format is:
wsl --import <Distro> <InstallLocation> <FileName> [Options]
<Distro>
: Name of the Distro we want to provide, you can add a suffix like_imported
(required).<InstallLocation>
: The location where we want to store the distro-related file (required).<FileName>
: The location and name that we exported earlier using thewsl --export
command (required).[Options]
: Optional parameters you can add.
Run the import command:
wsl --import Ubuntu-22.04_import E:\wslDistro\ E:\wslDistro\Ubuntu-22.04_export.tar
Run the New Distro
To list the WSL distributions:
wsl --list
You will see an extra distro that we just copied. To run the new distro:
wsl -d Ubuntu-22.04_import
To navigate to the root folder and then to your home folder:
cd ~
Now you can list files and folders:
ls
You can also view the instance and its data inside the Windows Explorer: