Home Swift UNIX C Assembly Go Web MCU Research Non-Tech

How to move installed WSL (Ubuntu) to another drive or location

2022-09-16 | UNIX | #Words: 452 | 中文原版

Recently, the C drive is almost full with using, and not empty much after cleaning it, so I plan to move WSL to a new drive. In the settings, “Ubuntu on Windows” has a “Move” button, but it is set to “cannot Move”. After spending a long time to try to cleaning, I found that it is better to move it to another drive, otherwise it will easily fill up.

Method and notices

After some research, I didn’t find a perfect implementation method, but I find a method that barely be regarded as a method, it is imperfect (why it is not perfect will be explained in detail later). The operation logic is:

  1. Export the current WSL as a compressed package (the compressed package is due to command restrictions and can speed up the movement. And the C drive is full, it is better to directly export to the target drive).
  2. Import the previously compressed WSL compressed package.

One thing you must notice: The reason why this method is not perfect is that all associated data and software will be lost. Because for import, need to log out and uninstall the old WSL to free up the full space and use the following commands to do:

wsl --unregister WSL_NAME_INSTALLED

This command will lost all settings, data and softwares of WSL.

=======2023-04-10======== You can back up your old WSL data and software from C:\Users\USERNAME\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu_79rhkp1fndgsc. This is the default path for WSL.

Export the WSL that needs to be moved

The first step is to export the WSL installed. The method is very simple.

Open PowerShell and use the following command:

wsl --export WSL_NAME_INSTALLE TARGET_PATH\CUSTOM_NAME.tar

For example, there is a WSL named “Ubuntu” located on the C drive. We want to move it to the G drive, and the output tar file is named “myUbuntu.tar”:

wsl --export Ubuntu G:\\WSL\myUbuntu.tar

Import WSL compressed package

Importing a compressed package is same as importing a distribution.

But you need free space of old WSL, so use following command:

wsl --unregister WSL_NAME_INSTELLED

This command will lost all settings, data and softwares of WSL.

This is an example as before:

wsl --unregister Ubuntu

Then import the WSL package:

wsl --import WSL_NAME PATH WSL_PACKAGE_PATH

For example:

wsl --import Ubuntu G:\\WSL G:\\WSL\myUbuntu.tar

It have moved to new position and you can re-open terminal to use, but lost all data.

I hope these will help someone in need~