From 72747f71376e38ebeb3203ad774f096d7710e82a Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Tue, 15 Sep 2020 01:21:18 +0000 Subject: [PATCH] fix WSL 2 install, update docs, separate installs --- wsl/README.md | 120 ++++++++++++++++++++++++++++++++---- wsl/install-wsl.ps1 | 44 ++++++++++++++ wsl/install.ps1 | 70 +++++++++++++++++++-- wsl1/README.md | 64 ++++++++++++++++++++ wsl1/install.ps1 | 13 ++++ wsl1/install.sh | 4 ++ wsl2/README.md | 137 ++++++++++++++++++------------------------ wsl2/install-wsl2.ps1 | 43 ++++++++++--- wsl2/install.ps1 | 59 ++++++++++++++++-- 9 files changed, 443 insertions(+), 111 deletions(-) create mode 100644 wsl/install-wsl.ps1 create mode 100644 wsl1/README.md create mode 100644 wsl1/install.ps1 create mode 100644 wsl1/install.sh diff --git a/wsl/README.md b/wsl/README.md index e0aaf26..f7bb8ef 100644 --- a/wsl/README.md +++ b/wsl/README.md @@ -1,14 +1,24 @@ --- -title: WSL -homepage: https://docs.microsoft.com/en-us/windows/wsl/install-win10 +title: WSL (Complete) +homepage: https://docs.microsoft.com/en-us/windows/wsl/wsl2-index tagline: | - WSL (Windows Subsystem for Linux) is required for running Microsoft Linux. + WSL (Windows Subsystem for Linux) runs a true Linux kernel via Hyper-V virtualization. --- +## Read Carefully! + +1. WSL is a **system** service which **requires Admin privileges** to install. +2. A **System Reboot** is **required** before WSL can be used. +3. Not all systems can use WSL 2, so **WSL 1** is the **default**. + ## Cheat Sheet -> WSL (v1) is not emulation, but rather a Linux syscall wrapper around the -> Windows Kernel. +> This is a complete WSL installer that includes **_WSL 1_**, **_WSL 2_** +> (Hyper-V), and **_Ubuntu Linux_**. +> +> WSL 2 is not "version 2" of WSL, but more "layer 2" WSL 1 uses a Linux syscall +> wrapper around the Windows Kernel 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: @@ -16,22 +26,108 @@ 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 +### How to Launch Linux + +To Launch the default Linux: + +```pwsh +wsl.exe +``` + +To Launch a specific Linux: + +```pwsh +wsl.exe --list +wsl.exe -d Ubuntu-20.04 +``` + +### How to Set or Reset Root Password + +```pwsh +wsl -d Ubuntu-20.04 -u root passwd +``` + +### How to Run a Single Command + +Assuming you want to run `ls ~/` as the default user: + +```pwsh +wsl -- ls ~/ +``` + +Assuming your username is `app` and you wanted to run `ls`: + +```pwsh +wsl -d Ubuntu-20.04 -u app -- ls ~/ +``` + +### How to Switch Between WSL 1 and WSL 2 + +Despite the name, WSL 2 is neither a "better" version of nor a replacement for +WSL 1. Rather WSL 1 uses a syscall wrapper (much like WINE) whereas WSL 2 uses +Hyper-V virtualization. + +You can start a Linux install in either mode and switch between the two as +desired. + +Either by setting the per Linux install: + +```pwsh +wsl --list --verbose +``` + +```pwsh +wsl --set-version Ubuntu-20.04 1 +# or +wsl --set-version Ubuntu-20.04 2 +``` + +Or by setting the global default: + +```pwsh +wsl --set-default-version 1 +# or +wsl --set-default-version 2 +``` + +Note that you _cannot_ set the mode before rebooting. + +See also . + +### How to Install Linux with PowerShell + +You can download Linux from the Windows Store, or with `curl.exe` on the Command +Line: + +```pwsh +curl.exe -L -o Ubuntu_2004_x64.appx https://aka.ms/wslubuntu2004 +powershell Add-AppxPackage Ubuntu_2004_x64.appx +``` + +See also . + +### Raw PowerShell Install Commands -It is not possible to install WSL without Admin privileges. +This is already detailed at [webinstall.dev/wsl1](https://webinstall.dev/wsl1) +and [webinstall.dev/wsl2](https://webinstall.dev/wsl2) -You _will_ need to allow the installer to run as Admin when asked. +See also -### Reboot Required +### Errors: Feature Not Installed & Nested VMs -You will not be able to use WSL without rebooting. +These errors are detailed at . -### Raw PowerShell Command +Likely solution: ```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'" +wsl --set-default-version 1 +wsl --set-version Ubuntu-20.04 1 ``` ## 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 +- https://docs.microsoft.com/en-us/windows/wsl/install-manual diff --git a/wsl/install-wsl.ps1 b/wsl/install-wsl.ps1 new file mode 100644 index 0000000..95b1cde --- /dev/null +++ b/wsl/install-wsl.ps1 @@ -0,0 +1,44 @@ +#!/usr/bin/env pwsh + +echo "Installing 1 of 5 Microsoft-Windows-Subsystem-Linux (for WSL 1 and WSL 2) ..." +& dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart + +echo "" +echo "Installing 2 of 5 VirtualMachinePlatform (for WSL 2 Hyper-V) ..." +& dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart + +Function Test-CommandExists +{ + Param ($command) + $oldPreference = $ErrorActionPreference + $ErrorActionPreference = 'stop' + try {if(Get-Command $command){RETURN $true}} + Catch {RETURN $false} + Finally {$ErrorActionPreference=$oldPreference} +} + +echo "" +IF(!(Test-CommandExists wsl)) +{ + echo "Skipping 3 of 5: Microsoft Linux Kernel requires WSL 1 to be installed first ..." +} +ELSE +{ + echo "Installing 3 of 5 Microsoft Linux Kernel (wsl_update_x64.msi for WSL 2) ..." + IF (!(Test-Path -Path "$Env:TEMP\wsl_update_x64.msi")) { + & curl.exe -f -o "$Env:TEMP\wsl_update_x64.msi" "https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi" + } + IF (!(Test-Path -Path "C:\Temp\System32\lxss\tools\kernel")) { + # NOTE: This WILL NOT work with TARGETDIR=$Env:TEMP!! + echo "Start-Process msiexec -Wait -ArgumentList '/a ""$Env:TEMP\wsl_update_x64.msi"" /quiet /qn TARGETDIR=""C:\Temp""'" + powershell -Command "Start-Process msiexec -Wait -ArgumentList '/a ""$Env:TEMP\wsl_update_x64.msi"" /quiet /qn TARGETDIR=""C:\Temp""'" + echo "Unpacked to C:\Temp\System32\lxss\tools\kernel" + } + Copy-Item -Path "C:\Temp\System32\lxss" -Destination "C:\System32" -Recurse -Force + echo "Copied to C:\System32\lxss\tools\kernel ..." + + echo "Start-Process msiexec -Wait -ArgumentList '/i','$Env:TEMP\wsl_update_x64.msi','/quiet','/qn'" + powershell -Command "Start-Process msiexec -Wait -ArgumentList '/i','$Env:TEMP\wsl_update_x64.msi','/quiet','/qn'" +} + +Start-Sleep -s 3 diff --git a/wsl/install.ps1 b/wsl/install.ps1 index ede5da3..849ead4 100644 --- a/wsl/install.ps1 +++ b/wsl/install.ps1 @@ -4,10 +4,70 @@ 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 +IF ($Env:WEBI_HOST -eq $null -or $Env:WEBI_HOST -eq "") { $Env:WEBI_HOST = "https://webinstall.dev" } -echo "!!!!!!!!!!!!!!!!!!!!!!!!!" -echo "!!! Reboot REQUIRED !!!" -echo "!!!!!!!!!!!!!!!!!!!!!!!!!" +# From https://devblogs.microsoft.com/scripting/use-a-powershell-function-to-see-if-a-command-exists/ +Function Test-CommandExists +{ + Param ($command) + $oldPreference = $ErrorActionPreference + $ErrorActionPreference = 'stop' + try {if(Get-Command $command){RETURN $true}} + Catch {RETURN $false} + Finally {$ErrorActionPreference=$oldPreference} +} + + +# $MYPWD = (Get-Item .).FullName +& curl.exe -fsSA "MS" -o "$Env:TEMP\install-wsl2.ps1" "$Env:WEBI_HOST/packages/wsl/install-wsl.ps1" +powershell -Command "Start-Process cmd -Wait -Verb RunAs -ArgumentList '/c cd /d %CD% && powershell -ExecutionPolicy Bypass $Env:TEMP\install-wsl2.ps1'" + +IF(!(Test-CommandExists wsl)) +{ + echo "Warning: Skipping 3 of 5: Reboot Required to install WSL 2 !!" +} + +echo "" +IF ((Test-Path -Path "$Env:UserProfile\Downloads\Ubuntu_2004_x64.appx" )) { + echo "Skipping 4 of 5: Ubuntu Linux 20.04 already installed" +} ELSE { + echo "Installing 4 of 5 Ubuntu Linux 20.04 (for WSL 1 and WSL 2) ..." + curl.exe -fL -o "$Env:UserProfile\Downloads\Ubuntu_2004_x64.appx.part" https://aka.ms/wslubuntu2004 + & move "$Env:UserProfile\Downloads\Ubuntu_2004_x64.appx.part" "$Env:UserProfile\Downloads\Ubuntu_2004_x64.appx" + Add-AppxPackage "$Env:UserProfile\Downloads\Ubuntu_2004_x64.appx" +} + +echo "" +echo "" +echo "" +echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" +echo "!!! !!!" +echo "!!! ACTION REQUIRED !!!" +echo "!!! READ CAREFULLY! !!!" +echo "!!! !!!" +echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + +IF(!(Test-CommandExists wsl)) +{ + echo "" + echo "WSL 2 was NOT installed yet. FOLLOW these instructions:" + echo "" + echo " 1. REBOOT you computer to finish the WSL 1 install" + echo " (either click Start Menu => Restart, or run 'shutdown /r /t 5')" + echo "" + echo " 2. RE-RUN this WSL 2 installer" + echo " (WSL 2 cannot finish installing until the WSL 1 install is complete)" + echo "" + echo " 3. WSL 2 must be enabled manually. See https://webinstall.dev/wsl2" + echo "" + + Exit +} + +echo "" +echo "You must ALSO run UBUNTU LINUX from the START MENU to complete the install." +echo "" +echo " - Select Ubuntu Linux from the Search menu or Start Menu" +echo " - Wait for the initialization to complete" +echo " - Choose a username (we recommend 'app') and a password" echo "" diff --git a/wsl1/README.md b/wsl1/README.md new file mode 100644 index 0000000..f5a2440 --- /dev/null +++ b/wsl1/README.md @@ -0,0 +1,64 @@ +--- +title: WSL 1 +homepage: https://docs.microsoft.com/en-us/windows/wsl/install-win10 +tagline: | + WSL 1 (Windows Subsystem for Linux) is required for running Microsoft Linux in Windows Terminal. +--- + +## Read Carefully! + +1. WSL is a **system** service which **requires Admin privileges** to install. +2. A **System Reboot** is **required** before WSL can be used. + +## Cheat Sheet + +> WSL 1 (also known as _Bash for Windows_) allows you to run _most_ Linux +> applications directly from within Windows. This is _NOT_ emulation, _NOR_ +> virtualization, but rather a a Linux syscall wrapper around the Windows +> Kernel. + +This will install **WSL 1 ONLY**. + +**Most people** want [WSL 1 + WSL 2 + Linux](https://webinstall.dev/wsl). \ +(WSL 2 is NOT a replacement for WSL 1, it's just another _layer_ of WSL) + +See the **Full Cheat Sheet** at . + +### How to Install Linux + +Once WSL is installed you can download Linux from the Windows Store. We +recommend: + +- [Ubuntu Linux 20.04](https://www.microsoft.com/store/apps/9n6svws3rx71) +- [Alpine WSL](https://www.microsoft.com/store/apps/9p804crf0395) + +### How to Switch to WSL 1 + +To set WSL 1 as the default: + +```pwsh +wsl --set-default-version 1 +``` + +To set WSL 1 for a specific Linux installation: + +1. List all installed Linux versions + ```pwsh + wsl --list + ``` +2. Set the desired version to WSL 2 with `--set-version`. For example: + ```pwsh + wsl --set-version Ubuntu-20.04 1 + ``` + +### How to Install WSL 1 with PowerShell + +This installer uses this command to install WSL 1 + +```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/wsl1/install.ps1 b/wsl1/install.ps1 new file mode 100644 index 0000000..ede5da3 --- /dev/null +++ b/wsl1/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/wsl1/install.sh b/wsl1/install.sh new file mode 100644 index 0000000..01ab542 --- /dev/null +++ b/wsl1/install.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +echo "WSL 1 (Windows Subsystem for Linux) can only be installed from Windows 10" +exit 0 diff --git a/wsl2/README.md b/wsl2/README.md index 41727a7..c109528 100644 --- a/wsl2/README.md +++ b/wsl2/README.md @@ -2,103 +2,56 @@ 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. + WSL2 (Windows Subsystem for Linux 2) runs a true Linux kernel via Hyper-V virtualization. --- -## 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) +## Read Carefully! -### Admin Privileges Required +1. WSL is a **system** service which **requires Admin privileges** to install. +2. A **System Reboot** is required **inbetween** install steps. -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. - -### How to Install Linux Bash - -You can download Linux from the Windows Store, or from the Command Line: - -```pwsh -curl.exe -L -o Ubuntu_2004_x64.appx https://aka.ms/wslubuntu2004 -powershell Add-AppxPackage Ubuntu_2004_x64.appx -``` - -See also . - -### How to Launch Linux - -To Launch the default Linux: - -```pwsh -wsl.exe -``` - -To Launch a specific Linux: +## Cheat Sheet -```pwsh -wsl.exe --list -wsl.exe -d Ubuntu-20.04 -``` +> WSL 2 uses `VirtualMachinePlatform` and Hyper-V to run a full Linux kernel +> with 100% syscall compatibility. However, it does not work on all computers +> and may not work in nested Virtual Machines - such as if running Windows in +> VirtualBox or Parallels on Mac or Linux. -### How to Set or Reset Root Password +This will install **WSL 1 and WSL 2 ONLY**. -```pwsh -wsl -d Ubuntu-20.04 -u root passwd -``` +**Most people** want [WSL 1 + WSL 2 + Linux](https://webinstall.dev/wsl). \ +(WSL 2 is NOT a replacement for WSL 1, it's just another _layer_ of WSL) -### How to Run a Single Command +See the **Full Cheat Sheet** at . -Assuming you want to run `ls ~/` as the default user: +### How to Install Linux -```pwsh -wsl -- ls ~/ -``` +Once WSL is installed you can download Linux from the Windows Store. We +recommend: -Assuming your username is `app` and you wanted to run `ls`: +- [Ubuntu Linux 20.04](https://www.microsoft.com/store/apps/9n6svws3rx71) +- [Alpine WSL](https://www.microsoft.com/store/apps/9p804crf0395) -```pwsh -wsl -d Ubuntu-20.04 -u app -- ls ~/ -``` +### How to Switch to WSL 2 Manually -### How to Switch Between WSL 1 and WSL 2 +To set WSL 2 for a specific Linux installation: -Despite the name, WSL 2 is neither a "better" version of nor a replacement for -WSL 1. Rather WSL 1 uses a syscall wrapper (much like WINE) whereas WSL 2 uses -Hyper-V virtualization. +1. List all installed Linux versions + ```pwsh + wsl --list --verbose + ``` +2. Set the desired version to WSL 2 with `--set-version`. For example: + ```pwsh + wsl --set-version Ubuntu-20.04 2 + ``` -After rebooting you can set WSL 2 as the default: +If WSL 2 works on your computer, you may set it 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 -``` - -See also . - -### Raw PowerShell Install Commands +### How to install WSL 2 with PowerShell If you'd like to install manually, or create your own script, this is how we do it: @@ -110,15 +63,39 @@ dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux # Install VirtualMachinePlatform dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart -# Download and Install WSL Update (contains Microsoft Linux kernel) +# Download and Install the WSL 2 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""'" +powershell -Command "Start-Process msiexec -Wait -ArgumentList '/a ""wsl_update_x64.msi"" /quiet /qn TARGETDIR=""C:\Temp""'" Copy-Item -Path "$env:TEMP\System32\lxss" -Destination "C:\System32" -Recurse + +# Also install the WSL 2 update with a normal full install +powershell -Command "Start-Process msiexec -Wait -ArgumentList '/i','wsl_update_x64.msi','/quiet','/qn'" ``` See also -### Nested VMs +### Error: Required Feature Not Installed + +> Installing, this may take a few minutes... +> +> Error: 0xXXXXXXXX The virtual machine could not be started because a required +> feature is not installed. + +It may be that your computer does not support virtualization because: + +- it lacks hardware support in the CPU for VTx +- VTx is disabled in the BIOS or EFI +- Virtualization has disabled in Windows 10 + +You should switch back to WSL 1 until you solve this problem: + +```pwsh +wsl --set-default-version 1 +wsl --list --verbose +wsl --set-version Ubuntu-20.04 1 +``` + +### Error: Nested Virtual Machines 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. diff --git a/wsl2/install-wsl2.ps1 b/wsl2/install-wsl2.ps1 index a7abcfd..3f419b9 100644 --- a/wsl2/install-wsl2.ps1 +++ b/wsl2/install-wsl2.ps1 @@ -7,16 +7,39 @@ echo "" echo "Installing 2 of 3 VirtualMachinePlatform ..." & dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart +Function Test-CommandExists +{ + Param ($command) + $oldPreference = $ErrorActionPreference + $ErrorActionPreference = 'stop' + try {if(Get-Command $command){RETURN $true}} + Catch {Write-Host “$command does not exist”; RETURN $false} + Finally {$ErrorActionPreference=$oldPreference} +} + 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" +IF(!(Test-CommandExists wsl)) +{ + echo "Skipping 3 of 3: Microsoft Linux Kernel requires WSL 1 to be installed first ..." +} +ELSE +{ + echo "Installing 3 of 3 Microsoft Linux Kernel (wsl_update_x64.msi) ..." + + IF (!(Test-Path -Path "$Env:TEMP\wsl_update_x64.msi")) { + & curl.exe -f -o "$Env:TEMP\wsl_update_x64.msi" "https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi" + } + IF (!(Test-Path -Path "C:\Temp\System32\lxss\tools\kernel")) { + # NOTE: This WILL NOT work with TARGETDIR=$Env:TEMP!! + echo "Start-Process msiexec -Wait -ArgumentList '/a ""$Env:TEMP\wsl_update_x64.msi"" /quiet /qn TARGETDIR=""C:\Temp""'" + powershell -Command "Start-Process msiexec -Wait -ArgumentList '/a ""$Env:TEMP\wsl_update_x64.msi"" /quiet /qn TARGETDIR=""C:\Temp""'" + echo "Unpacked to C:\Temp\System32\lxss\tools\kernel" + } + Copy-Item -Path "C:\Temp\System32\lxss" -Destination "C:\System32" -Recurse -Force + echo "Copied to C:\System32\lxss\tools\kernel ..." -Copy-Item -Path "$env:TEMP\System32\lxss" -Destination "C:\System32" -Recurse -echo "Installed C:\System32\lxss\tools\kernel ..." + echo "Start-Process msiexec -Wait -ArgumentList '/i','$Env:TEMP\wsl_update_x64.msi','/quiet','/qn'" + powershell -Command "Start-Process msiexec -Wait -ArgumentList '/i','$Env:TEMP\wsl_update_x64.msi','/quiet','/qn'" +} -Start-Sleep -s 2 +Start-Sleep -s 3 diff --git a/wsl2/install.ps1 b/wsl2/install.ps1 index c5f40ea..c1cd83a 100644 --- a/wsl2/install.ps1 +++ b/wsl2/install.ps1 @@ -10,9 +10,60 @@ $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'" +# From https://devblogs.microsoft.com/scripting/use-a-powershell-function-to-see-if-a-command-exists/ +Function Test-CommandExists +{ + Param ($command) + $oldPreference = $ErrorActionPreference + $ErrorActionPreference = 'stop' + try {if(Get-Command $command){RETURN $true}} + Catch {RETURN $false} + Finally {$ErrorActionPreference=$oldPreference} +} + +IF(!(Test-CommandExists wsl)) +{ + echo "" + echo "" + echo "" + echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + echo "!!! !!!" + echo "!!! READ CAREFULLY !!!" + echo "!!! !!!" + echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + echo "" + echo "WSL 2 was NOT installed yet. You MUST follow these instructions:" + echo "" + echo " 1. REBOOT you computer to finish the WSL 1 install" + echo " (either click Start Menu => Restart, or run 'shutdown /r /t 5')" + echo "" + echo " 2. RE-RUN this WSL 2 installer" + echo " (WSL 2 cannot finish installing until the WSL 1 install is complete)" + echo "" + echo " 3. Download and Install Linux" + echo " (see https://webinstall.dev/wsl2)" + echo "" + + Exit +} + +echo "" +echo "" +echo "" +echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" +echo "!!! !!!" +echo "!!! READ CAREFULLY !!!" +echo "!!! !!!" +echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" +echo "" +echo "WSL 2 is now installed, HOWEVER, you MUST:" +echo "" +echo "However, you still MUST INSTALL LINUX:" +echo "" +echo " 1. Download and Install Ubuntu Linux" +echo " (see https://webinstall.dev/wsl2)" echo "" -echo "!!!!!!!!!!!!!!!!!!!!!!!!!" -echo "!!! Reboot REQUIRED !!!" -echo "!!!!!!!!!!!!!!!!!!!!!!!!!" +echo " 2. Set WSL to use WSL 2 with Hyper-V. For example:" +echo " wsl.exe --set-version Ubuntu-20.04 2" +echo " wsl.exe --set-default-version 2" echo "" -echo "WSL 2 will be available to use after rebooting." -- 2.25.1