Portable WSL2

less than 1 minute read

Description:

So while I was troubleshooting permissions with WSL not being able to create folders with my Docker container, I first tried installing WSL on a secondary drive and setting that as my default WSL instance (since this is where my media was stored anyways). Here are the steps to set it up:

To Resolve:

  1. Open Powershell and type:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    
    Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
    New-Item D:\Ubuntu -ItemType Directory
    Set-Location D:\Ubuntu
    Invoke-WebRequest -Uri https://aka.ms/wslubuntu2004 -OutFile Ubuntu.appx -UseBasicParsing
    Rename-Item .\Ubuntu.appx Ubuntu.zip
    Expand-Archive .\Ubuntu.zip -Verbose
    cd ./Ubuntu
    cmd
    ubuntu2004.exe
    # create user/pass
    apt-get update -y && apt-get upgrade -y
    
    # close and reopen powershell
    wsl -l -v
    NAME      STATE           VERSION
    * Legacy    Stopped         1
    Ubuntu-20.04    Running     1
       
    wsl --set-version Ubuntu-20.04 2
    wsl --set-default-version 2
    wsl --set-default Ubuntu-20.04
    wsl -l -v
    NAME      STATE           VERSION
    Ubuntu-20.04    Running     2
    * Legacy    Stopped         1
    
  2. I don’t remember if the commands were exactly like that, but that was the overall idea.

Comments