Skip to content

Instantly share code, notes, and snippets.

@vunhatchuong
Last active August 17, 2024 07:58
Show Gist options
  • Select an option

  • Save vunhatchuong/4a71b7894aa98f74993cf03b99d5b5ad to your computer and use it in GitHub Desktop.

Select an option

Save vunhatchuong/4a71b7894aa98f74993cf03b99d5b5ad to your computer and use it in GitHub Desktop.
Move WSL2 location

Guide

Move WSL2 OS installation location to another location.

Check available distros:

wsl --list

Stop the running distro

wsl -t {Distro}

Export

wsl --export {Distro} "D:/{Distro}.tar" 

Unregister

wsl --unregister {Distro}

Make a new location

mkdir D:/WSL

Import to the new location

wsl --import {Distro} "D:/WSL/{Distro}" "D:/{Distro}.tar"

Set it as default

wsl --set-default {Distro}

Confirmation

$ Get-ChildItem "HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss" -Recurse

    Hive: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss

Name                           Property
----                           --------
{b43db7ed-9ac2-435b-8b9b-4b4f3 State            : 1
d044f53}                       DistributionName : {Distro}
                               Version          : 2
                               BasePath         : \\?\D:\WSL\{Distro}
                               Flags            : 15
                               DefaultUid       : 1000

Extras

  • Get location of WSL from explorer: \\wsl.localhost\{Distro}
  • Access Windows drive: ls /mnt/

Resources

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