Last active
June 15, 2020 16:46
-
-
Save doitian/d89bf7b67067c1f4dcbeef066e2a4639 to your computer and use it in GitHub Desktop.
A script to simplify WSL installation via lxrunoffline https://github.com/DDoSolitary/LxRunOffline/wiki
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param ( | |
[Parameter(Mandatory=$true, Position=0)] | |
[ValidateScript({ | |
if(-Not (Test-Path $_)) { | |
throw "File does not exist" | |
} | |
return $true | |
})] | |
[System.IO.FileInfo] | |
$RootFsTar, | |
[String] | |
$Name | |
) | |
$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" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It will install WSL into the directory where this script is in.
Usage