Windows 10 version 1903 (May 2019 Update) added new Windows wsl command-line options to import, export and unregister Linux environment with TAR format file on the root file system.
Content Summary
How to Export/Backup Linux System
How to Import/Restore Linux System
How to Unregister/Delete Linux System
How to Export/Backup Linux System
Step 1: PowerShell or Command Prompt environment in order to execute wsl command (wsl.exe). Right click Start button or press Windows + x and then click Windows PowerShell.
Step 2: To list the distros installed, run the following command: wsl --list
Step 3: Use the following command to export distro’s file system to TAR file: wsl --export distro_name file_name.tar
For example, to export Ubuntu 18.04 system to ubuntu.tar, Execute: wsl --export Ubuntu-18.04 ubuntu.tar
Step 4: A TAR file containing Linux distribution’s file system created.
How to Import/Restore Linux System
Use wsl command with –import option to import a TAR file created: wsl --import distro_name install_location file_name.tar
For example, in order to import distro from TAR file located at C:\Users\Chris\ubuntu.tar, call it “Ubuntu-18.04,” and store it at C:\Users\Chris\ubuntu. execute: wsl --import Ubuntu-18.04 C:\Users\Chris\ubuntu C:\Users\Chris\ubuntu.tar
If you want to match where Windows normally installs them to by default, they’re generally in their own folder in C:\Users\NAME\AppData\Local\Packages.
For example, you might want to put Ubuntu in C:\Users\NAME\AppData\Local\Packages\Ubuntu.
How to Unregister/Delete Linux System
Uninstall distro with –unregister option along with its name. This will result in all the Linux distribution’s files being deleted.
Step 1: Use the following command to see all installed distributions: wsl --list
Step 2: Specify the distribution you want to delete: wsl --unregister distro_name
For example, if it’s called Ubuntu-18.04, you’d run: wsl --unregister Ubuntu-18.04