Skip to content

WSL import and export workflow

The WSL import and export workflow involves using Windows PowerShell commands to manage WSL distributions by exporting them to tar archives and subsequently importing them to create new instances.^[600-developer-tools-windows-wsl-command.md]

Exporting a Distribution

To create a portable backup of an existing WSL instance, the wsl --export command is used. This operation packages the file system of the specified distribution into a single .tar file.^[600-developer-tools-windows-wsl-command.md]

For example, to export the default "Ubuntu-20.04" distribution, the following command creates a tar archive named Ubuntu-20.04-20220121.tar: wsl --export Ubuntu-20.04 ./Ubuntu-20.04-20220121.tar^[600-developer-tools-windows-wsl-command.md]

Importing a Distribution

Creating a new WSL environment from an exported image is done using the wsl --import command. This command requires specifying the desired distribution name, the installation path (storage location), and the path to the source tar file.^[600-developer-tools-windows-wsl-command.md]

The syntax follows this structure: wsl --import <DistributionName> <InstallLocation> <FileName>^[600-developer-tools-windows-wsl-command.md]

Post-Import Configuration

After importing a fresh image, it is common practice to terminate the instance to ensure settings take effect and then configure the root user and default user accounts.^[600-developer-tools-windows-wsl-command.md]

Termination The specific WSL instance can be stopped using: wsl --terminate <DistributionName>^[600-developer-tools-windows-wsl-command.md]

User Management Configuration typically involves launching the distribution as the root user to set passwords and define a default non-root user via the /etc/wsl.conf file.^[600-developer-tools-windows-wsl-command.md]

Cleanup and Management

To remove a registered WSL distribution from the system, the wsl --unregister command is used.^[600-developer-tools-windows-wsl-command.md]

The current state of registered distributions can be verified using: wsl --list --verbose^[600-developer-tools-windows-wsl-command.md]

Sources

^[600-developer-tools-windows-wsl-command.md]