Moving Docker and WSL (Ubuntu) Data to Another Drive
If you are a gamer like me you probably will need all that sweet, sweet, space in your C drive for all the fun and games, and this guide provides detailed instructions to move Docker and WSL (Ubuntu) data from the C: drive to the D: drive using symbolic links, ensuring compatibility with existing configurations.
Prerequisites
- Open PowerShell as Administrator:
- Right-click on the Start menu and select Windows PowerShell (Admin).
- Back up important data:
- Make sure to back up any critical data before proceeding.
Part 1: Moving Docker Data to D:
Step 1: Move Docker Folder to the New Drive
- Navigate to Docker's Current Data Location:
- Open File Explorer and go to
C:\Users\YourUserName\AppData\Local\Docker
. - Move the Entire
Docker
Folder: - Cut and paste the
Docker
folder toD:\Docker
. After moving, the folder structure should look like:D:\Docker\wsl\data
Step 2: Recreate Docker Folder Structure on C:
- Open Command Prompt as Administrator:
- Press
Win + R
, typecmd
, then pressCtrl + Shift + Enter
. - Recreate the Necessary Folder Structure:
- Run the following command:
cmd mkdir "C:\Users\YourUserName\AppData\Local\Docker\wsl"
Step 3: Create a Symbolic Link for Docker Data
- Create the Symbolic Link:
- Run this command in the same Command Prompt:
cmd mklink /D "C:\Users\YourUserName\AppData\Local\Docker\wsl\data" "D:\Docker\wsl\data"
Step 4: Verify the Docker Symbolic Link
- Check the Link:
- In File Explorer, navigate to
C:\Users\YourUserName\AppData\Local\Docker\wsl
and verify thatdata
appears as a shortcut pointing toD:\Docker\wsl\data
.
Step 5: Restart Docker
- Start Docker Desktop:
- Open Docker Desktop and ensure it starts without any errors. If successful, Docker is now using the data at
D:\Docker\wsl\data
.
Part 2: Moving WSL (Ubuntu) Data to D:
Step 1: Export the WSL (Ubuntu) Distribution
- Run the Export Command:
- In PowerShell (Admin), export your WSL distribution (e.g., Ubuntu) to a
.tar
file:powershell wsl --export Ubuntu D:\WSLBackup\Ubuntu.tar
- This creates a backup file named
Ubuntu.tar
inD:\WSLBackup
. - Confirm the Backup:
- Check that
Ubuntu.tar
is present inD:\WSLBackup
.
Step 2: Unregister the WSL Distribution
- Remove the Current Installation:
- Run the following command in PowerShell to unregister Ubuntu:
powershell wsl --unregister Ubuntu
- This removes Ubuntu from WSL without deleting the backup file.
Step 3: Import Ubuntu to D:
- Import Ubuntu Using the Backup File:
- Run the following command to import Ubuntu to the
D:
drive:powershell wsl --import Ubuntu D:\WSL\Ubuntu D:\WSLBackup\Ubuntu.tar --version 2
- This imports the Ubuntu distribution to
D:\WSL\Ubuntu
, creating a newext4.vhdx
file in that location.
Step 4: Verify the New WSL Data Location
- Check for
ext4.vhdx
: - Navigate to
D:\WSL\Ubuntu
in File Explorer and confirm the presence of theext4.vhdx
file, which contains your WSL data.
Part 3: Create a Symbolic Link for WSL (Ubuntu) Data
Step 1: Recreate the Folder Structure on C:
- Open Command Prompt as Administrator:
- If not already open, press
Win + R
, typecmd
, and pressCtrl + Shift + Enter
. - Recreate the Necessary Folder Structure:
- Run the following command:
cmd mkdir "C:\Users\YourUserName\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu_79rhkp1fndgsc\LocalState"
Step 2: Create a Symbolic Link for Ubuntu Data
- Create the Symbolic Link:
- Run this command in Command Prompt:
cmd mklink /D "C:\Users\YourUserName\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu_79rhkp1fndgsc\LocalState\ext4.vhdx" "D:\WSL\Ubuntu\ext4.vhdx"
Step 3: Verify the Ubuntu Symbolic Link
- Check the Link:
- Navigate to
C:\Users\YourUserName\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu_79rhkp1fndgsc\LocalState
and verify thatext4.vhdx
appears as a shortcut toD:\WSL\Ubuntu\ext4.vhdx
.
Step 4: Start WSL and Test
- Run Ubuntu:
- Start Ubuntu using the following command in PowerShell:
powershell wsl -d Ubuntu
- If Ubuntu starts without any issues, it is now successfully using
D:\WSL\Ubuntu\ext4.vhdx
for its data.
Summary
After following these steps, both Docker and WSL (Ubuntu) data have been moved to the D:
drive. Symbolic links on the C:
drive ensure compatibility with their original locations.