Skip to content

Instantly share code, notes, and snippets.

@cjonesy
Last active April 27, 2023 21:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cjonesy/94b975558a0e3d4c7e8f3fab5f17b9cb to your computer and use it in GitHub Desktop.
Save cjonesy/94b975558a0e3d4c7e8f3fab5f17b9cb to your computer and use it in GitHub Desktop.
WSL Setup

WSL Setup

Install WSL

Open up powershell and run the following command to install, and upgrade WSL:

wsl --install
wsl --update Ubuntu 2

Perimeter81 VPN fixes for WSL

P81 does not support IPV6, and struggles to resolve DNS on the VPN when using the VPN Interface's DNS. If we do not change these settings DNS resolution will take significantly longer when connected to VPN.

  1. Disable IPV6 as P81 doesn't support it currently
  • In powershell, run the following:
    Set-Content -Path "$env:userprofile/.wslconfig" -Value @"
    [wsl2]
    kernelCommandLine=ipv6.disable=1
    "@
  1. Configure P81 to use VPN Interface DNS
    • Open P81
    • Select settings
    • Toggle "Use VPN Interface DNS" setting off

Create Rocky WSL Image

WSL Images can be created from Docker Images. Here we pull down the latest Rocky 9 Image, extract it, and import it into WSL.

In Powershell run the following:

mkdir C:\wsl\rocky
iwr -OutFile C:\wsl\Rocky-9.tar.xz -Uri https://dl.rockylinux.org/pub/rocky/9/images/x86_64/Rocky-9-Container-Base.latest.x86_64.tar.xz
wsl --import Rocky C:\wsl\rocky\ C:\wsl\Rocky-9.tar.xz --version 2

Now that we have imported the image, we can finish setting things up inside the WSL image.

From Powershell run wsl -d Rocky to open a bash shell inside Rocky.

Inside the bash shell, run the following commands to setup your user inside WSL:

dnf update -y && dnf install passwd sudo git wget -y
USERNAME=$(cmd.exe /c "echo %USERNAME%" |sed 's/[^[:alpha:]]/_/g;s/[[:upper:]]/\L&/g;s/_$//')
adduser -G wheel $USERNAME
echo -e "[user]\ndefault=$USERNAME" >> /etc/wsl.conf
echo -e "[automount]\noptions=\"metadata\"" >> /etc/wsl.conf
passwd $USERNAME
exit

You should now be back at your Powershell prompt. From here we will restart the WSL image so the changes take effect.

Run the following command:

wsl --terminate Rocky

Now, when you start WSL Rocky image you should be running as your own user:

PS C:\Users\Charlie Jones> wsl -d Rocky

/mnt/c/Users/Charlie Jones
❯ whoami
charlie_jones
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment