Skip to content

Instantly share code, notes, and snippets.

@doitian doitian/Install-WSL.ps1
Last active Jun 15, 2020

What would you like to do?
A script to simplify WSL installation via lxrunoffline
param (
[Parameter(Mandatory=$true, Position=0)]
if(-Not (Test-Path $_)) {
throw "File does not exist"
return $true
$ErrorActionPreference = "Stop"
$WSLRoot = $PSScriptRoot
$ExtractDir = "."
if ($RootFsTar.Name.StartsWith('alpine-')) {
$DefaultName = 'Alpine'
} elseif ($RootFsTar.Name.StartsWith('fedora-')) {
$DefaultName = 'Fedora'
if ($Name.Length -eq 0) {
$Name = $DefaultName
lxrunoffline.exe i -n $Name -f $RootFsTar -d "$WSLRoot\$Name" -v 2 -r "$ExtractDir"
if (-Not (Test-Path -LiteralPath "$WSLRoot\$Name\ext4.vhdx")) {
wsl --set-version $Name 2
rm -Re -Fo "$WSLRoot\$Name\temp"

This comment has been minimized.

Copy link
Owner Author

doitian commented Jun 14, 2020

It will install WSL into the directory where this script is in.


.\Install-WSL.ps1 -Name Alpine .\alpine-minirootfs-3.12.0-x86_64.tar.gz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.