Moving WSL Distros to a Different Drive on Windows 11 and 10: A Step-by-Step Guide
- To relocate a WSL distribution to a different hard drive on Windows 11 (or 10), navigate to Settings > Apps > Installed apps, select the Linux distribution you want to move, and choose the “Move” option to specify the new drive.
- Another option is to launch Command Prompt (admin) and execute the command
wsl --manage DISTRO --move NEW-DRIVE
or utilize theexport
andimport
commands for the same purpose.
When working with the Windows Subsystem for Linux (WSL), the installation location for your Linux distributions cannot be chosen initially. Nonetheless, moving an already installed distribution to another drive is feasible, and this guide will walk you through the necessary steps.
On Windows 11 (or 10), numerous components of WSL are interspersed across the OS installation, particularly within the “System32” directory. This configuration complicates the process of moving or installing the WSL setup and its Linux distributions to a different location.
Fortunately, there are several ways to shift your Linux distributions to a new drive. You can use the WSL --move
command to transfer the current distribution or achieve this by exporting the Linux installation from its original drive and importing it back using the --import
command. An even simpler method is to use the move functionality directly from the Settings app.
This guide provides a structured approach to moving your Linux distros via WSL to a different location on Windows 11 (or 10).
- Relocate Linux distribution using Settings
- Relocate Linux distribution using the Move command
- Relocate Linux distribution using the Import command
Relocate Linux distribution using Settings
To transfer a WSL distro to a new location via the Settings app, follow these steps:
- Open Start.
- Search for Command Prompt, right-click the top result, and select Run as administrator.
- Enter the following command to shut down any active Linux distribution, then press Enter:
wsl --shutdown
- Access Settings.
- Select Apps.
- Navigate to the Installed apps section.
- Expand the menu for the desired distro and select the Move option.
- Select the new drive for your Linux distribution.
- Click the Move button.
Completing these steps will transfer the necessary files to run the WSL distro to the chosen drive.
Relocate Linux distribution using the Move command
To move a WSL distribution to another drive, adhere to these steps:
- Open Start.
- Search for Command Prompt, right-click on the top result, and select Run as administrator.
- Execute the following command to list all distributions installed on your machine and press Enter:
wsl --list --all
- Input the command to shut down any running distribution and press Enter:
wsl --shutdown
- Enter the command to relocate a WSL distro to the desired drive and press Enter:
wsl --manage Ubuntu --move F:\WSL\Ubuntu
Replace “Ubuntu” with the actual name of your distribution, and “F:\WSL\Ubuntu” with the new destination path.
- To run the Linux distribution from its new location, type the following command and press Enter:
wsl -d Ubuntu
In this command, substitute “Ubuntu” with your specific Linux installation name.
Upon completion, the distro should operate from the designated new drive.
If you encounter the error message “Failed to attach disk ‘F:\Path\to\ext4.vhdx’ to WSL2: Access is denied. Error code: Wsl/Service/CreateInstance/MountVhd/HCS/E_ACCESSDENIED” , execute the wsl --shutdown
command again, followed by wsl -d DISTRO-NAME
. This error often arises if you attempt to start the distribution via the Start menu immediately after moving it to the new location.
If you manage several Linux distributions, it is advisable to create a main folder (Ctrl + Shift + N) on the new hard drive and a unique folder for each WSL distro inside this main directory. Each distribution’s files are contained in a “.vhdx” file with an identical “ext4” name, and having multiple files with the same name will cause conflicts.
As a point of reference, when a Linux distribution is installed using WSL, it is placed in the %USERPROFILE%\AppData\Local\Packages\
directory—the same location where other Windows applications are installed. Furthermore, the virtual drive housing the distro files is kept within the package, specifically under the “LocalState” folder.
Relocate Linux distribution using Import command
To shift a Linux distro using the WSL import command, follow these steps:
- Open Start.
- Search for Command Prompt, right-click the top result, and select Run as administrator.
- Use the command below to list the distros currently installed on your system and press Enter:
wsl --list --all
- Shut down any running distribution by inputting the command and pressing Enter:
wsl --shutdown
- Run the command to export a Linux distro and press Enter:
wsl --export Kali-linux kali-export.tar
Change “Kali-linux” to the name of the distribution you want to export, and specify the name for the “.tar” file. The exported package will be saved at the root of the “C” drive.
- Execute the command to unregister the Linux instance from your system and press Enter:
wsl --unregister Kali-linux
Make sure to replace “Kali-linux” with the name of the distribution you are removing from your main system drive.
- Lastly, to import the WSL distro into the new location, type the following command and press Enter:
wsl --import Kali-linux F:\WSL\Kali-linux C:\kali-export.tar
In this command, substitute “Kali-linux” with your distro name, “F:\WSL\Kali-linux” with the path where you want the distribution saved, and “C:\kali-export.tar” with the directory and name of the exported file.
Once these steps are completed, the WSL distribution will be operational from its new location.
Leave a Reply