Difference between revisions of "Wsl2 new"
Jump to navigation
Jump to search
(Created page with "Install Ubuntu 22.04 instance ``` $ErrorActionPreference = "Stop" $distributionName = "example1" $distrib = "ubuntu-22.04" $installLocation = "C:\WSL\$distributionName" $ta...") |
|||
Line 1: | Line 1: | ||
− | Install Ubuntu 22.04 instance | + | # WSL2 Install, Routing & Options |
+ | |||
+ | ## Install Ubuntu 22.04 instance | ||
``` | ``` | ||
Line 22: | Line 24: | ||
``` | ``` | ||
− | # Routing fixes if needed | + | ## Routing fixes if needed |
``` | ``` | ||
$interfaceAlias = "vEthernet (WSL (Hyper-V firewall))" | $interfaceAlias = "vEthernet (WSL (Hyper-V firewall))" |
Latest revision as of 17:46, 23 August 2024
WSL2 Install, Routing & Options
Install Ubuntu 22.04 instance
$ErrorActionPreference = "Stop" $distributionName = "example1" $distrib = "ubuntu-22.04" $installLocation = "C:\WSL\$distributionName" $tarballUrl = "https://cloud-images.ubuntu.com/releases/jammy/release/${distrib}-server-cloudimg-amd64-root.tar.xz" $tarballPath = "$env:TEMP\${distrib}.tar.gz" wsl --set-default-version 2 Invoke-WebRequest -Uri $tarballUrl -OutFile $tarballPath wsl --import $distributionName $installLocation $tarballPath wsl -d $distributionName -u root -- bash -c "adduser --disabled-password --gecos '' newuser && usermod -aG sudo newuser" wsl -d $distributionName -- bash -c "echo -e '[user]\ndefault=newuser' > /etc/wsl.conf" # Remove-Item $tarballPath Write-Output "WSL distribution '$distributionName' with $distrib has been installed and configured."
Routing fixes if needed
$interfaceAlias = "vEthernet (WSL (Hyper-V firewall))" $interfaceName = "usb" $vpnInterfaceRegex = "PANGP*" $vpnDNS = "10.x.x.y" $ipOfDefaultGatewayIPRouteToDelete = "192.168.1.1" $ErrorActionPreference = "Stop" if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { $arguments = "& '" + $myInvocation.MyCommand.Definition + "'" Start-Process powershell -Verb runAs -ArgumentList $arguments exit } Get-NetIPInterface -InterfaceAlias $interfaceAlias | Set-NetIPInterface -InterfaceMetric 1 Get-NetAdapter | Where-Object { $_.InterfaceDescription -like $vpnInterfaceRegex } | Set-NetIPInterface -InterfaceMetric 4000 Set-DnsClientServerAddress -InterfaceAlias $interfaceName -ServerAddresses ($vpnDNS) route delete 0.0.0.0 MASK 0.0.0.0 $ipOfDefaultGatewayIPRouteToDelete