Skip to content

WSL import and export management

WSL (Windows Subsystem for Linux) provides mechanisms to export and import distributions, allowing for backup, migration, or the cloning of specific environments (such as Ubuntu).^[400-devops-02-os-and-linux-basics-windows-wsl.md]

Exporting a distribution

To create a backup of a specific distribution, the wsl --export command is used. This command packages the file system of the specified distribution into a TAR archive.

wsl --export Ubuntu-20.04 ./Ubuntu-20.04-20220121.tar
```^[400-devops-02-os-and-linux-basics-windows-wsl.md]

## Importing a distribution

To create a new distribution from a previously exported TAR file, the `wsl --import` command is used^[400-devops-02-os-and-linux-basics-windows-wsl.md].

### Command syntax

The command requires specifying the name for the new distribution, the installation path (storage location), and the path to the source TAR file^[400-devops-02-os-and-linux-basics-windows-wsl.md].

```powershell
wsl --import <DistributionName> <InstallLocation> <FileName>

Example

The following example creates a new distribution named U20.04-tommy using an Ubuntu image located at D:\install\wsl-work\image\, storing the instance at D:\install\wsl-work\storage\Ubuntu-20.04-tommy^[400-devops-02-os-and-linux-basics-windows-wsl.md].

wsl --import U20.04-tommy D:\install\wsl-work\storage\Ubuntu-20.04-tommy D:\install\wsl-work\image\Ubuntu-20.04-20220121.tar

Managing distributions

After import and export operations, you may need to manage the lifecycle of the distributions, such as terminating active sessions or removing unneeded instances^[400-devops-02-os-and-linux-basics-windows-wsl.md].

Listing distributions

To view all installed distributions and their states, use the list command with the verbose flag^[400-devops-02-os-and-linux-basics-windows-wsl.md].

wsl --list --verbose
# OR
wsl -l -v

Terminating a distribution

To stop a running distribution, use the --terminate command followed by the distribution name^[400-devops-02-os-and-linux-basics-windows-wsl.md].

wsl --terminate U20.04-tommy

Unregistering (Removing) a distribution

To completely delete a distribution from WSL, use the --unregister command^[400-devops-02-os-and-linux-basics-windows-wsl.md].

wsl --unregister U20.04-tommy

Sources

  • 400-devops-02-os-and-linux-basics-windows-wsl.md