From 4b19fbc17727bd1a422e292eb617ea0acd680f0a Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Mon, 14 Sep 2020 12:01:16 +0000 Subject: [PATCH] add wsl and wsl2 --- wsl/README.md | 37 +++++++++++++++++++++ wsl/install.ps1 | 13 ++++++++ wsl/install.sh | 4 +++ wsl2/README.md | 77 +++++++++++++++++++++++++++++++++++++++++++ wsl2/install-wsl2.ps1 | 22 +++++++++++++ wsl2/install.ps1 | 18 ++++++++++ wsl2/install.sh | 4 +++ 7 files changed, 175 insertions(+) create mode 100644 wsl/README.md create mode 100644 wsl/install.ps1 create mode 100644 wsl/install.sh create mode 100644 wsl2/README.md create mode 100644 wsl2/install-wsl2.ps1 create mode 100644 wsl2/install.ps1 create mode 100644 wsl2/install.sh diff --git a/wsl/README.md b/wsl/README.md new file mode 100644 index 0000000..e0aaf26 --- /dev/null +++ b/wsl/README.md @@ -0,0 +1,37 @@ +--- +title: WSL +homepage: https://docs.microsoft.com/en-us/windows/wsl/install-win10 +tagline: | + WSL (Windows Subsystem for Linux) is required for running Microsoft Linux. +--- + +## Cheat Sheet + +> WSL (v1) is not emulation, but rather a Linux syscall wrapper around the +> Windows Kernel. + +After installing WSL and **Rebooting** you will be able to install Linux +variants from the Windows 10 Store: + +- [Ubuntu Linux 20.04](https://www.microsoft.com/store/apps/9n6svws3rx71) +- [Alpine WSL](https://www.microsoft.com/store/apps/9p804crf0395) + +### Admin Privileges Required + +It is not possible to install WSL without Admin privileges. + +You _will_ need to allow the installer to run as Admin when asked. + +### Reboot Required + +You will not be able to use WSL without rebooting. + +### Raw PowerShell Command + +```pwsh +powershell -Command "Start-Process cmd -Verb RunAs -ArgumentList '/c cd /d %CD% && dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart'" +``` + +## References + +- https://docs.microsoft.com/en-us/windows/wsl/install-win10 diff --git a/wsl/install.ps1 b/wsl/install.ps1 new file mode 100644 index 0000000..ede5da3 --- /dev/null +++ b/wsl/install.ps1 @@ -0,0 +1,13 @@ +#!/usr/bin/env pwsh + +echo "Installing WSL (Windows Subsystem for Linux) ..." +echo "" +echo "Security: requires administrator approval to install" + +powershell -Command "Start-Process cmd -Verb RunAs -ArgumentList '/c cd /d %CD% && dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all'" +# /norestart + +echo "!!!!!!!!!!!!!!!!!!!!!!!!!" +echo "!!! Reboot REQUIRED !!!" +echo "!!!!!!!!!!!!!!!!!!!!!!!!!" +echo "" diff --git a/wsl/install.sh b/wsl/install.sh new file mode 100644 index 0000000..43439b0 --- /dev/null +++ b/wsl/install.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +echo "WSL (Windows Subsystem for Linux) can only be installed from Windows 10" +exit 0 diff --git a/wsl2/README.md b/wsl2/README.md new file mode 100644 index 0000000..f03a0f6 --- /dev/null +++ b/wsl2/README.md @@ -0,0 +1,77 @@ +--- +title: WSL 2 (Hyper-V) +homepage: https://docs.microsoft.com/en-us/windows/wsl/wsl2-index +tagline: | + WSL2 (Windows Subsystem for Linux 2) runs a true Linux kernel via Hyper-V emulation. +--- + +## Cheat Sheet + +> WSL 2 uses `VirtualMachinePlatform` and Hyper-V to run a full Linux kernel +> with 100% syscall compatibility. + +After installing WSL and **Rebooting** you will be able to install Linux +variants from the Windows 10 Store: + +- [Ubuntu Linux 20.04](https://www.microsoft.com/store/apps/9n6svws3rx71) +- [Alpine WSL](https://www.microsoft.com/store/apps/9p804crf0395) + +### Admin Privileges Required + +It is not possible to install WSL without Admin privileges. + +You _will_ need to allow the installer to run as Admin when asked. + +### Reboot Required + +You will not be able to use WSL without rebooting. + +### Switching Between WSL and WSL 2 + +After rebooting you can set WSL 2 as the default: + +```pwsh +wsl --set-default-version 2 +``` + +You can list your existing WSL Linuxes: + +```pwsh +wsl --list --verbose +``` + +And you can switch between using WSL and WSL 2 without an issues: + +```pwsh +wsl --set-version Ubuntu 2 +``` + +### Raw PowerShell Install Commands + +If you'd like to install manually, or create your own script, this is how we do +it: + +```pwsh +# Install WSL 1 +dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart + +# Install VirtualMachinePlatform +dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart + +# Download and Install WSL Update (contains Microsoft Linux kernel) +& curl.exe -f -o wsl_update_x64.msi "https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi" +powershell -Command "Start-Process msiexec -Wait -ArgumentList '/a wsl_update_x64.msi /qb TARGETDIR=""$env:TEMP""'" +Copy-Item -Path "$env:TEMP\System32\lxss" -Destination "C:\System32" -Recurse +``` + +### Nested VMs + +WSL2 may not work properly if you are already running Windows inside of a +Virtual Machine, especially if MacOS or Linux is the VM Host. + +## References + +- https://docs.microsoft.com/en-us/windows/wsl/install-win10 +- https://github.com/microsoft/WSL/issues/5014 +- https://docs.microsoft.com/en-us/windows/wsl/wsl2-index +- https://aka.ms/wsl2kernel diff --git a/wsl2/install-wsl2.ps1 b/wsl2/install-wsl2.ps1 new file mode 100644 index 0000000..a7abcfd --- /dev/null +++ b/wsl2/install-wsl2.ps1 @@ -0,0 +1,22 @@ +#!/usr/bin/env pwsh + +echo "Installing 1 of 3 Microsoft-Windows-Subsystem-Linux ..." +& dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart + +echo "" +echo "Installing 2 of 3 VirtualMachinePlatform ..." +& dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart + +echo "" +echo "Installing 3 of 3 Microsoft Linux Kernel (wsl_update_x64.msi) ..." +& curl.exe -f -o wsl_update_x64.msi "https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi" +# TODO could we do /quiet /qn to get rid of the popup? +powershell -Command "Start-Process msiexec -Wait -ArgumentList '/a wsl_update_x64.msi /quiet /qn TARGETDIR=""$env:TEMP""'" +#& msiexec /a "wsl_update_x64.msi" /qb TARGETDIR="$env:TEMP" +#Start-Sleep -s 10 +echo "Copied to $env:TEMP" + +Copy-Item -Path "$env:TEMP\System32\lxss" -Destination "C:\System32" -Recurse +echo "Installed C:\System32\lxss\tools\kernel ..." + +Start-Sleep -s 2 diff --git a/wsl2/install.ps1 b/wsl2/install.ps1 new file mode 100644 index 0000000..c5f40ea --- /dev/null +++ b/wsl2/install.ps1 @@ -0,0 +1,18 @@ +#!/usr/bin/env pwsh + +echo "Installing WSL 2 (Windows Subsystem for Linux with Hyper-V) ..." +echo "" +echo "Security: requires administrator approval to install" + +IF ($Env:WEBI_HOST -eq $null -or $Env:WEBI_HOST -eq "") { $Env:WEBI_HOST = "https://webinstall.dev" } + +$MYPWD = (Get-Item .).FullName +& curl.exe -fA "MS" -o "$Env:TEMP\install-wsl2.ps1" "$Env:WEBI_HOST/packages/wsl2/install-wsl2.ps1" +powershell -Command "Start-Process cmd -Wait -Verb RunAs -ArgumentList '/c cd /d %CD% && powershell -ExecutionPolicy Bypass $Env:TEMP\install-wsl2.ps1'" + +echo "" +echo "!!!!!!!!!!!!!!!!!!!!!!!!!" +echo "!!! Reboot REQUIRED !!!" +echo "!!!!!!!!!!!!!!!!!!!!!!!!!" +echo "" +echo "WSL 2 will be available to use after rebooting." diff --git a/wsl2/install.sh b/wsl2/install.sh new file mode 100644 index 0000000..d5edcb9 --- /dev/null +++ b/wsl2/install.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +echo "WSL 2 (Windows Subsystem for Linux with Hyper-V) can only be installed from Windows 10" +exit 0 -- 2.25.1