Backup and move WSL2 between disks

Are you experiencing sluggish performance in your WSL (Windows Subsystem for Linux) environment? Do your git commands within WSL take an eternity to complete? If so, you're not alone. By default, WSL is set to use the C drive, and when it runs out of space or if your project is stored in a different filesystem, it can significantly impact performance.

The good news is that there's a solution. In this article, we'll explore how to move your WSL2 installation to another filesystem, alleviating the slow performance and improving your overall experience. By transferring your WSL2 to a different disk, you can regain the speed and efficiency you need for your development workflows.

If you're tired of waiting for WSL and git commands to respond, it's time to take action. Join us as we delve into the steps required to move your WSL2 installation and say goodbye to the sluggishness that has been holding you back. Let's dive in and reclaim your WSL2 performance.

Full Solution

Step by Step

  1. Open PowerShell and execute the following command to list your WSL2 distributions and their names:
wsl --list -v
  1. Identify the name of your WSL2 distribution from the list.

  2. Shutdown the WSL2 distribution using the following command, replacing <DistributionName> with the actual name of your WSL2 distribution:

wsl --shutdown <DistributionName>
  1. Export the WSL2 distribution to a folder of your choice using the command:
wsl --export <DistributionName> "D:\kali-wsl.tar"

Replace <DistributionName> with the name of your WSL2 distribution and "D:\kali-wsl.tar with the desired export path and filename.

  1. Unregister the WSL2 distribution by executing the command:
wsl --unregister <DistributionName>

Again, replace <DistributionName> with the name of your WSL2 distribution.

  1. Import the WSL2 distribution to the desired folder and register it with the following command:
wsl --import <DistributionName> "F:\new_position\kali" "D:\kali-wsl.tar"

Ensure you replace <DistributionName> with the name of your WSL2 distribution, "F:\new_position\kali" with the desired import path, and "D:\kali-wsl.tar" with the path to the exported tar file.

  1. You can now use the WSL2 distribution in the new filesystem location specified in step 6.

In this guide, you have learned how to effectively backup and move your WSL2 installation between disks. By following the provided steps, you can overcome performance issues, optimize your workflow, and seamlessly transition your WSL2 environment to a new filesystem.

Did you find this article valuable?

Support Mohamed El Hedi Attia by becoming a sponsor. Any amount is appreciated!