Move WSL2 Distro To A Different Drive

Move WSL2 Distro To A Different Drive

This guide explains how to move a Linux distribution installed on a Windows Subsystem for Linux (WSL) to another drive. In this example, we will be moving an Ubuntu 22.04 distribution, and the steps are outlined below.

Prerequisites

  • Windows operating system with WSL 2 installed.

Instructions

  1. Check the existing WSL 2 installations on your computer by running the following command in a WSL or Command Prompt window: 

  2. If the installation you want to move is running, you must stop it. For example, if you want to move Ubuntu 22.04, terminate it using the following command: 

  3. Export the WSL distribution to a folder. In this example, we will export Ubuntu 22.04 ubuntu-ex.tar to the D:\wsl\wsl_export directory. Run the following command:

    
    

    wsl --export Ubuntu-24.04 "D:\wsl_export\ubuntu-ex.tar" 

  4. Unregister the previous WSL installation. This step removes the Ubuntu 22.04 distribution from the WSL 2 list obtained in the previous step. Execute the following command:

    
    

    wsl --unregister Ubuntu-24.04

  5. Import the WSL installation to a new folder and re-register it. In this example, we will import Ubuntu 22.04 to the D:\wsl_import\ubuntu directory using the exported ubuntu-ex.tar file. Run the following command:

    
    

    wsl --import Ubuntu-24.04 "D:\wsl_import\ubuntu" "D:\wsl_export\ubuntu-ex.tar"

  6. Set default user (optional): This step is only necessary if you’re: Importing to a new machine or creating a new user for Ubuntu. Setting the default user avoids login prompts each time you launch the distribution.

    Using multiple users on your Windows machine and want different defaults for each. This clarifies which user launches by default for each WSL environment.

    To set the default user, run (replace “me” with your actual username):

    ubuntu config --default-user me

    If you installed Ubuntu 24.04, run (replace “me” with your actual username):

    
    

    ubuntu2404 config --default-user me

Congratulations! You have successfully moved your WSL distribution (Ubuntu 24.04) to another drive. You can start the distribution and continue using it in the new location.

Don’t hesitate to create pull requests if you have suggestions for improvements to this guide. Your contributions are greatly appreciated!

Leave a Comment

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *