Learning and Sharing
  • Home
  • Blog
  • Linux
  • macOS
  • Virtualization
    • VMware
    • VirtualBox
  • Windows
    • Windows 11
    • Windows 10
    • Windows Server
  • Series
    • Symantec
    • Intune
    • Microsoft Azure
    • Powershell
    • VirtualBox
    • VMware
    • PowerShell Learning
    • Microsoft Graph
  • More
    • Auto Installation
    • AEC Installation
  • Contact
No Result
View All Result
  • Home
  • Blog
  • Linux
  • macOS
  • Virtualization
    • VMware
    • VirtualBox
  • Windows
    • Windows 11
    • Windows 10
    • Windows Server
  • Series
    • Symantec
    • Intune
    • Microsoft Azure
    • Powershell
    • VirtualBox
    • VMware
    • PowerShell Learning
    • Microsoft Graph
  • More
    • Auto Installation
    • AEC Installation
  • Contact
No Result
View All Result
No Result
View All Result

How to Move WSL to Another Machine or Drive in Windows

July 21, 2024
in A, Blog, WSL
1
ADVERTISEMENT

Table of Contents

In some cases, you want to move an installed WSL instance to another drive instead of the system drive (C:). For example, you want to backup or preventing any mistake when re-installing Windows.

PS C:\Users\admin> wsl -l -v
NAME            STATE           VERSION
Ubuntu          Running         2
kali-linux      Stopped         2

Default installation location in WSL

In this post, only Ubuntu is installed. The path to the VHD file of the WSL distribution is stored in the BasePath registry parameter under the registry key.

HKCU\Software\Microsoft\Windows\CurrentVersion\Lxss
Bg1760

Alternatively, you can open the default installation location of WSL using below PowerShell command:

Invoke-Item $env:LOCALAPPDATA\Packages

From here, you can determine your WSL distributions by its name. Then navigate to each folder, you can see the virtual disk of each instance (ext4.vhdx).

Bg1761

Move an WSL instance to another location

1. First, run the WSL instance and check the username. In our example, it is bon.

bon@DESKTOP-K34B7Q9:~$ whoami
bon

2. Close all apps running in your Linux environment and WSL console:

wsl --shutdown

3. In order to backup (export) your WSL instance and save it to G:\backup, run the below commands to create a folder to store the exported file then export the instance:

mkdir G:\backup
wsl --export Ubuntu 'G:\backup\ubuntu.tar'

4. Wait till the WSL export is over (it may take much time). A .tar archive with your WSL ext4 file system will appear in the target directory.

#Output
PS C:\> wsl --export Ubuntu G:\backup\ubuntu.tar
Export in progress, this may take a few minutes.
The operation completed successfully.
Bg1762

5. Then you may remove the WSL instance and its files on the source disk (on the system drive).

wsl --unregister Ubuntu

6. Create a new directory for your Linux instance. The instance would be installed on that path. For example, we’ll import the instance on G:\wsl directory. Then import the .tar archive to WSL using this command:

mkdir G:\wsl
wsl --import Ubuntu 'G:\wsl' 'G:\backup\ubuntu.tar'
Note Tips: In this step, you can change the instance name as you need instead of using the default one.

For example, this instance run as a webserver, so we’ll import it with that name. When we get the list of instances in WSL, we can recognize it easier.

wsl --import webserver 'G:\wsl' 'G:\backup\ubuntu.tar'
#Output
PS C:\> wsl --import webserver 'G:\wsl' 'G:\backup\ubuntu.tar'
Import in progress, this may take a few minutes.
The operation completed successfully.

PS C:\Users\admin> wsl -l -v
  NAME         STATE           VERSION
* webserver    Stopped         2

7. After imported the instance. The default login to Ubuntu is root. If it’s no problem, you’ve done to move a WSL instance to another location.

PS C:\Users\admin> wsl -d webserver
Welcome to Ubuntu 22.04.2 LTS (GNU/Linux 5.15.90.4-microsoft-standard-WSL2 x86_64)

root@DESKTOP-K34B7Q9:/mnt/c/Users/admin# whoami
root

Configure the default user

In case, you want to change the username to another username (we got it earlier – bon). You can run the below commands:

ubuntu.exe config --default-user bon

Start the WSL environment. This time, the shell uses the username same as the username in the first time you are installing the instance.

PS C:\> wsl -d ubuntu
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

bon@DESKTOP-K34B7Q9:/mnt/c/$

Note: You may use the same scenario to move a configured WSL image to other computers.

ADVERTISEMENT

Not a reader? Watch this related video tutorial:

5/5 - (1 vote)
Previous Post

How to Reset Default Profile Picture in Windows 11

Next Post

Windows Subsystem for Linux Has No Installed Distributions

Related Posts

Images Hidden Due To Mature Content Settings In CivitAI

August 31, 2024

Azure OpenAI vs Azure AI Hub, How to Choose the Right One for Your Needs

August 20, 2024

Running Hyper-V and VMware Workstation on The Same Machine

August 15, 2024

How to Uninstall All Autodesk Products At Once Silently

July 29, 2024
Ftr5

How to Uninstall the Autodesk Genuine Service on Windows

July 29, 2024

How to Remove The Test Mode Watermark Without Disabling Test Mode

July 28, 2024

Comments 1

  1. Mathin Ahmed says:
    1 year ago

    Facing Wsl/Service/RegisterDistro/0x80070050 while doing the webserver part. Can you help me ?

    Reply

Leave a Reply Cancel reply

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

Recent Posts

  • How To Turn On uBlock Origin Extension in Chrome (2025)
  • Images Hidden Due To Mature Content Settings In CivitAI
  • Azure OpenAI vs Azure AI Hub, How to Choose the Right One for Your Needs

Categories

Stay in Touch

Discord Server

Join the Discord server with the site members for all questions and discussions.

Telegram Community

Jump in Telegram server. Ask questions and discuss everything with the site members.

Youtube Channel

Watch more videos, learning and sharing with Leo ❤❤❤. Sharing to be better.

Newsletter

Join the movement and receive our weekly Tech related newsletter. It’s Free.

General

Microsoft Windows

Microsoft Office

VMware

VirtualBox

Technology

PowerShell

Microsoft 365

Microsoft Teams

Email Servers

Copyright 2025 © All rights Reserved. Design by Leo with ❤

No Result
View All Result
  • Home
  • Linux
  • Intune
  • macOS
  • VMware
  • VirtualBox
  • Powershell
  • Windows 10
  • Windows 11
  • Microsoft 365
  • Microsoft Azure
  • Microsoft Office
  • Active Directory

No Result
View All Result
  • Home
  • Linux
  • Intune
  • macOS
  • VMware
  • VirtualBox
  • Powershell
  • Windows 10
  • Windows 11
  • Microsoft 365
  • Microsoft Azure
  • Microsoft Office
  • Active Directory