Move WSL to different drive

Windows Subsystem for Linux is awesome, but it may benefit from storing its drives (VHD's) on another disk.

List containers

You can run this command to list all containers. Each container has a volume attached (VHD) and can operate independently. Usually, you'll have one container for your usage (the default) - but other tools may make their own - like Docker Desktop which now uses the WSL system to run docker in.

wsl --list

The output may look like:

Windows Subsystem for Linux Distributions:
ubuntu (Default)
docker-desktop-data
docker-desktop

Move a container

Before moving a container, I can recommend shutting down WSL. This will probably preempt issues of all sorts.

wsl --shutdown

Each container can be moved with:

wsl --export ubuntu N:\ubuntu.tar
wsl --unregister ubuntu
wsl --import ubuntu N:\WSL\ubuntu N:\ubuntu.tar --version 2

The above commands export a named container, "ubuntu" to a tar file. Then we remove the container and re-register it in a new location.

The file can be deleted afterwards.

Michael Bisbjerg

Michael Bisbjerg