WSL (Windows Subsystem for Linux) is a great tool provided by Windows 10 (OS build 20262 or higher) that enables developers to run Linux machines in Windows platform without third-party application like Virtual Box.
With support of installed WSL, you can install any Linux distribution available in Microsoft Store. After installation of a Linux distribution, for example Ubuntu 18.04, WSL stored its machine data in %APPDATA%\Local\Packages\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc\LocalState
.
If you need to move the data to another directory/drive in your computer to free some spaces in your main drive, you can perform these following commands.
1. List all distributions in your computer.
wsl --list --verbose
2. Export the distribution data.
wsl --export <distribution-name> <any-file-name>.tar
For example, distribution name is Ubuntu-18.04:
wsl --export Ubuntu-18.04 exported-ubuntu-18-04.tar
3. Unregister the distribution.
wsl --unregister Ubuntu-18.04
After this step, file ext4.vhdx
which is previously located in LocalState directory should has been unavailable.
4. Import the exported data into new directory/drive you desired.
wsl --import Ubuntu-18.04 X:\path\to\new\location\Ubuntu-18.04 .\exported-ubuntu-18-04.tar
5. Change WSL to WSL version 2 if required.
wsl --set-version Ubuntu-18.04 2
This method can also be used for managing Docker Desktop for Windows data. Latest Docker Desktop for Windows is suggested to be installed using WSL support. After Docker Desktop installation, if you run wsl --list
, there will be docker-desktop
and docker-desktop-data
records. Any containers you build using Docker Desktop are available in docker-desktop-data
. For migrating the storage used, you can run these following commands.
wsl --export docker-desktop-data docker-data.tar
wsl --unregister docker-desktop-data
wsl --import docker-desktop-data /path/to/new/location ./docker-data.tar
Comments
Post a Comment