Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save taufiqibrahim/bf271935e8a77090ac503fb04f81ed85 to your computer and use it in GitHub Desktop.
Save taufiqibrahim/bf271935e8a77090ac503fb04f81ed85 to your computer and use it in GitHub Desktop.

Move WSL2 from C to another drive

Run powershell.exe as Administrator

#Command
wsl -l -v

#Output example
PS C:\WINDOWS\system32> wsl -l -v
  NAME            STATE           VERSION
* Ubuntu-18.04    Running         2

Create new directory on Drive D

Create new directory on D:\ so we have new directory D:\wsls.

Export current Ubuntu-18 to D:\wsls\ using this command

#Command
wsl --export Ubuntu-18.04 D:\wsls\ubuntu-18.04-wsl.tar

#Output example
PS C:\WINDOWS\system32> wsl --export Ubuntu-18.04 D:\wsls\ubuntu-18.04-wsl.tar

Create new directory for new VMs

Create VMs directory under D:\wsls so we will have D:\wsls\VMs.

cd D:\wsls\VMs\
mkdir ubuntu-18.04-wsl

Unregister current WSL

wsl --unregister Ubuntu-18.04

#Output example
PS D:\wsls\VMs> wsl --unregister Ubuntu-18.04
Unregistering...

Import exported image into new directory

wsl --import Ubuntu-18.04 D:\wsls\VMs\ubuntu-18.04-wsl D:\wsls\ubuntu-18.04-wsl.tar

Check for the new Ubuntu-18

wsl -l
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment