Skip to content

Instantly share code, notes, and snippets.

@doitian
Last active June 15, 2020 16:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save doitian/d89bf7b67067c1f4dcbeef066e2a4639 to your computer and use it in GitHub Desktop.
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
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"
}
@doitian
Copy link
Author

doitian commented Jun 14, 2020

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

Usage

.\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