From fc3e717e47c7359db3703e11e6ce00a266f08d75 Mon Sep 17 00:00:00 2001 From: David Geeraerts Date: Fri, 19 Mar 2021 13:53:13 -0700 Subject: [PATCH] Version 1.0.0 - see change log --- Changelog.md | 26 ++++ Install_Chocolatey.cmd | 2 + README.md | 11 +- WSL2-Setup-Guide.md | 112 +++++++++++++ WSL_Setup.cmd | 345 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 495 insertions(+), 1 deletion(-) create mode 100644 Changelog.md create mode 100644 Install_Chocolatey.cmd create mode 100644 WSL2-Setup-Guide.md create mode 100644 WSL_Setup.cmd diff --git a/Changelog.md b/Changelog.md new file mode 100644 index 0000000..99d53ae --- /dev/null +++ b/Changelog.md @@ -0,0 +1,26 @@ +# ChangeLog: ADDS (Active Directory Domain Services) Tool + + +## Features Heading +- `Added` for new features. +- `Changed` for changes in existing functionality. +- `Fixed` for any bug fixes. +- `Removed` for now removed features. +- `Security` in case of vulnerabilities. +- `Deprecated` for soon-to-be removed features. + +[//]: # (Copy paste pallette) +[//]: # (#### Added) +[//]: # (#### Changed) +[//]: # (#### Fixed) +[//]: # (#### Removed) +[//]: # (#### Security) +[//]: # (#### Deprecated) + +--- + +## Version 1.0.0 Build: 2021-03-19 + +- First relase + +--- \ No newline at end of file diff --git a/Install_Chocolatey.cmd b/Install_Chocolatey.cmd new file mode 100644 index 0000000..b4ace88 --- /dev/null +++ b/Install_Chocolatey.cmd @@ -0,0 +1,2 @@ +@powershell -NoProfile -ExecutionPolicy unrestricted -Command "(iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))) >$null 2>&1" && SET PATH="%PATH%;%ALLUSERSPROFILE%\chocolatey\bin" +exit /B \ No newline at end of file diff --git a/README.md b/README.md index c86699d..2403ba1 100644 --- a/README.md +++ b/README.md @@ -1 +1,10 @@ -WSL +# [Windows Subsystem for Linux Version 2](https://docs.microsoft.com/en-us/windows/wsl/) + +Use the installation guide to install and setup WSL +(https://github.com/cal-sc/WSL/WSL2-Setup-Guide.md) + +Use instllation script for automated installation: + +[WSL_Setup.cmd](https://github.com/cal-sc/WSL/archive/refs/tags/v1.0.0.zip) + +If you run the automated setup, the computer must reboot, and you must run WSL_Setup.cmd a second time to complete the installation. \ No newline at end of file diff --git a/WSL2-Setup-Guide.md b/WSL2-Setup-Guide.md new file mode 100644 index 0000000..30ea085 --- /dev/null +++ b/WSL2-Setup-Guide.md @@ -0,0 +1,112 @@ +# [Windows Subsystem for Linux Version 2](https://docs.microsoft.com/en-us/windows/wsl/) + + +1. Add the following Windows features: + - Windows Subsystem for Linux (WSL required) + + `dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart` + + - Virtual Machine Platform (WSL2) + + `dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart` + +2. Windows needs to be rebooted. + + `shutdown /r /t 10 /c "WSL Setup" /d p:2:4` + +3. Install [Linux Kernel update package](https://docs.microsoft.com/en-us/windows/wsl/install-win10#step-4---download-the-linux-kernel-update-package) + + + [_Direct link to msi_](https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi) + +``` + cd %PUBLIC%\Downloads + wget "https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi" + wsl_update_x64.msi /passive /q /forcerestart +``` + +4. Set WSL 2 as default + + `wsl --set-default-version 2` + +5. [Install Linux distro's from Microsoft Store](https://docs.microsoft.com/en-us/windows/wsl/install-win10#step-6---install-your-linux-distribution-of-choice) + + [MS WSL Store](https://aka.ms/wslstore) + + `wsl --list --online` # Doesn't work + + [Chocolatey Repo](https://chocolatey.org/packages?q=WSL) + + [_Requires Chocolatey to be installed!_](https://docs.chocolatey.org/en-us/choco/setup#install-from-powershell-v3) + + ``` + choco install wsl-alpine /y + choco install wsl-ubuntu-2004 /y + choco install wsl-archlinux /y + choco install wsl-fedoraremix /y + choco install wsl-debiangnulinux /y + choco install wsl-kalilinux /y + choco install wsl-opensuse /y + choco wsl-kalilinux wsl-opensuse /y + ``` + +Install multiple at once: + + choco install wsl-alpine wsl-ubuntu-2004 wsl-archlinux wsl-fedoraremix wsl-debiangnulinux /y + +6. Set username and password for distro + +7. Update distribution with package manager + + [**Debian Lineage**] + + `apt update` + + `apt upgrade` + + [**RHEL Lineage**] + + `dnf upgrade --refresh` + + [**Alpine Lineage**] + + `apk update` + + `apk upgrade` + +### Notes: +- all files by default are located in the user profile: + + `C:\Users\\AppData\Local\Packages` + +- main file is a virtual harddisk: **ext4.vhdx** + +- Change location for a distro + + [EXPORT] + + `wsl.exe --export ` + + [IMPORT] + + `wsl.exe --import [Options]` + +- To access wsl linux distro file system from Windows + + `\\wsl$\` + +- LAN Networking (port proxy) + + `netsh interface portproxy add v4tov4 listenport= listenaddress=0.0.0.0 connectport= connectaddress=` + + e.g. `netsh interface portproxy add v4tov4 listenport=4000 listenaddress=0.0.0.0 connectport=4000 connectaddress=192.168.101.100` + +- Default storage capacity is up to 256 GB + + To expand, follow the following [instructions.](https://docs.microsoft.com/en-us/windows/wsl/compare-versions#expanding-the-size-of-your-wsl-2-virtual-hard-disk) + + +#### Limitations +- Cross file system is slow, i.e. linux internally using windows files. +- no pre-built CENTOS distro +- no IPv6 support \ No newline at end of file diff --git a/WSL_Setup.cmd b/WSL_Setup.cmd new file mode 100644 index 0000000..1215e8e --- /dev/null +++ b/WSL_Setup.cmd @@ -0,0 +1,345 @@ +:::: Windows Subsystem for Linux [WSL] :::: + +::############################################################################# +:: #DESCRIPTION# +:: +:: SCRIPT STYLE: Interactive +:: Automated installation and setup for Windows Subsystem for Linux (WSL) +:: +::############################################################################# + +:::: Developer :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:: Author: David Geeraerts +:: Location: Olympia, Washington USA +:: E-Mail: dgeeraerts.evergreen@gmail.com +::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + +:::: GitHub ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:: https://github.com/cal-sc/WSL +::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + +:::: License :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:: Copyleft License(s) +:: GNU GPL v3 (General Public License) +:: https://www.gnu.org/licenses/gpl-3.0.en.html +::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + +:::: Versioning Schema :::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:: VERSIONING INFORMATION :: +:: Semantic Versioning used :: +:: http://semver.org/ :: +:: Major.Minor.Revision :: +::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + + +:::: Command shell :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +@Echo Off +@SETLOCAL enableextensions +SET $PROGRAM_NAME=WSL_Setup +SET $Version=1.0.0 +SET $BUILD=2021-03-19 10:00 +Title %$PROGRAM_NAME% +Prompt WSL$G +color 8F +mode con:cols=75 lines=40 +::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + + +:::: Configuration - Basic :::::::::::::::::::::::::::::::::::::::::::::::::::: +:: Declare Global variables +:: All User variables are set within here. +:: Defaults +:: uses user profile location for logs +SET "$LOGPATH=%APPDATA%\WSL" +SET "$LOG=WSL_Setup.log +::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + + +:::: Configuration - Advanced ::::::::::::::::::::::::::::::::::::::::::::::::: +:: Advanced Settings + +:: DEBUG +:: {0 [Off/No] , 1 [On/Yes]} +SET $DEGUB_MODE=0 + + +::############################################################################# +:: !!!! Everything below here is 'hard-coded' [DO NOT MODIFY] !!!! +::############################################################################# + + +:::: Default Program Variables :::::::::::::::::::::::::::::::::::::::::::::::: +:: Program Variables +SET $STATUS_ADMIN= +SET $STATUS_VT= +SET $STATUS_MICROSOFT-WINDOWS-SUBSYSTEM-LINUX= +SET $STATUS_VIRTUALMACHINEPLATFORM= +SET $STATUS_REBOOT= +SET $STATUS_WSL_KERNEL_UPDATE= +SET $STATUS_WSL_DEFAULT_VERSION= + +::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + +:::: Check if complete :::::::::::::::::::::::::::::::::::::::::::::::::::::::: +IF EXIST "%$LOGPATH%\WSL-Setup_Complete.txt" GoTo end +::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + +:::: Directory :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:CD + :: Launched from directory + SET "$PROGRAM_PATH=%~dp0" + :: Setup logging + IF NOT EXIST "%$LOGPATH%\var" MD "%$LOGPATH%\var" + cd /D "%$PROGRAM_PATH%" +::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + +:::: Administrator Privilege Check :::::::::::::::::::::::::::::::::::::::::::: +:subA + SET $ADMIN_STATUS=0 + openfiles.exe 1> "%$LOGPATH%\var\var_$Admin_Status_M.txt" 2> "%$LOGPATH%\var\var_$Admin_Status_E.txt" && (SET $ADMIN_STATUS=1) +::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + +Goto start + +:::: banner ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:banner +:: CONSOLE MENU :: +cls + echo ******************************************************************** + echo %$PROGRAM_NAME% + echo Version: %$Version% + IF %$DEGUB_MODE% EQU 1 echo Build: %$BUILD% + echo. + echo %DATE% %TIME% + echo. + echo ******************************************************************** +echo. +GoTo:EOF +::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + +:::: HUD :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:HUD +echo -------------------------------------------------------------------- +echo Part I +echo Administrative Privelage: %$STATUS_ADMIN% +echo Virtualization: %$STATUS_VT% +echo Feature Microsoft-Windows-Subsystem-Linux: %$STATUS_MICROSOFT-WINDOWS-SUBSYSTEM-LINUX% +echo Feature VirtualMachinePlatform: %$STATUS_VIRTUALMACHINEPLATFORM% +echo Reboot: %$STATUS_REBOOT% +echo -------------------------------------------------------------------- +echo. +echo Part II +echo WSL Kernel update: %$STATUS_WSL_KERNEL_UPDATE% +echo Set WSL Default version [2]: %$STATUS_WSL_DEFAULT_VERSION% +echo -------------------------------------------------------------------- +GoTo:EOF +::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + +:::: Start :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:start + CALL :banner + CALL :HUD + echo. +::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + +:::: Admin Privelage Check :::::::::::::::::::::::::::::::::::::::::::::::::::: +:admin + echo Checking if running with Administrative privelage... + echo (Running with Administrative privelage is required!) + echo. + IF %$ADMIN_STATUS% EQU 1 ( + echo Running with Administrative privelage! + SET $STATUS_ADMIN=Pass + ) + + IF %$ADMIN_STATUS% EQU 0 ( + color 4E + echo NOT running with Administrative privelage! + echo Right-click script, "Run as administrator"! + echo Script will now abort! + echo. + SET $STATUS_ADMIN=FAILED + pause + GoTo end + ) + echo. +::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + +:checkPI +IF EXIST "%$LOGPATH%\var\Part-I-Reboot.txt" ( + SET $STATUS_VT=Done + SET $STATUS_MICROSOFT-WINDOWS-SUBSYSTEM-LINUX=Done + SET $STATUS_VIRTUALMACHINEPLATFORM=Done + SET $STATUS_REBOOT=Done + GoTo PartII + ) +::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + +::::Virtualization Check :::::::::::::::::::::::::::::::::::::::::::::::::::::: +:VT + CALL :banner + CALL :HUD +SET $VT_CHECK=0 + +echo. +echo Checking to see if: +echo [VT] Virtualization Enabled In Firmware (BIOS) is turned on... +echo. +wmic CPU GET VirtualizationFirmwareEnabled /VALUE > "%$LOGPATH%\var\$VirtualizationFirmwareEnabled.txt" +wmic CPU GET VMMonitorModeExtensions /VALUE > "%$LOGPATH%\var\$VMMonitorModeExtensions.txt" +wmic CPU GET SecondLevelAddressTranslationExtensions /VALUE > "%$LOGPATH%\var\$SecondLevelAddressTranslationExtensions.txt" +find /I "VirtualizationFirmwareEnabled=TRUE" "%$LOGPATH%\var\$VirtualizationFirmwareEnabled.txt" 1> nul 2> nul && (SET $VT_CHECK=1) +echo %$VT_CHECK% > "%$LOGPATH%\var\$VT_CHECK.txt" +IF %$VT_CHECK% EQU 1 ECHO Virtualization Enabled in the firmware, i.e. BIOS! +SET $STATUS_VT=Check +echo. +IF %$VT_CHECK% EQU 1 GoTo skipVT + echo Hyper-V virtualization not detected! + echo Searching for hypervisor... + systeminfo | FIND /I "Hyper-V Requirements:" > "%$LOGPATH%\var\$HYPER-V_REQUIREMENTS.txt" + SET $HYPERVISOR=0 + echo $HYPERVISOR: %$HYPERVISOR% > "%$LOGPATH%\var\$HYPERVISOR.txt" + FIND /I "A hypervisor has been detected." "%$LOGPATH%\var\$HYPER-V_REQUIREMENTS.txt" 1> nul 2> nul && (SET $HYPERVISOR=1) + IF %$HYPERVISOR% EQU 0 GoTo skipHypervisor + echo A non-hyper-V hypervisor has been detected! + echo Do you want to proceed anyway? + Choice /c YN /m "[Y]es or [N]o": + IF %ERRORLEVEL% EQU 2 GoTo errHyper + IF %ERRORLEVEL% EQU 1 GoTo skipVT + +:errHyper + color 4E + echo Virtualization disabled in the firmware ^(BIOS^)! + echo ...or non-Hyper-V hypervisor detected! + echo. + echo Virtualization is required for Hyper-V and WSL! + echo Turn on [VT] Virtualization in the BIOS. + echo Script will now abort! + echo. + SET $STATUS_VT=FAILED + PAUSE + GoTo end + +:skipVT +::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + +CALL :banner +CALL :HUD +IF DEFINED ChocolateyInstall GoTo skipChoco +echo Install Chocolatey, Windows package manager? +echo (Linux distro's can be installed via Chocolatey!) +echo. +Choice /c YN /m "[Y]es or [N]o": + IF %ERRORLEVEL% EQU 2 GoTo skipChoco + IF %ERRORLEVEL% EQU 1 GoTo Choco_I + +:Choco_I +CALL Install_Chocolatey.cmd +:skipChoco +::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + +CALL :banner +CALL :HUD + +:::: DISM ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +Dism /online /Get-FeatureInfo /FeatureName:Microsoft-Windows-Subsystem-Linux > "%$LOGPATH%\var\$FEATURE_MICROSOFT-WINDOWS-SUBSYSTEM-LINUX.txt" +FIND /I "State : Enabled" "%$LOGPATH%\var\$FEATURE_MICROSOFT-WINDOWS-SUBSYSTEM-LINUX.txt" 1> nul 2> nul && (SET $STATUS_MICROSOFT-WINDOWS-SUBSYSTEM-LINUX=Check) && GoTo skipFMWSL +dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart +SET $STATUS_MICROSOFT-WINDOWS-SUBSYSTEM-LINUX=Done +:skipFMWSL + +CALL :banner +CALL :HUD +Dism /online /Get-FeatureInfo /FeatureName:VirtualMachinePlatform > "%$LOGPATH%\var\$VIRTUALMACHINEPLATFORM.txt" +FIND /I "State : Enabled" "%$LOGPATH%\var\$VIRTUALMACHINEPLATFORM.txt" 1> nul 2> nul && (SET $STATUS_VIRTUALMACHINEPLATFORM=Check) && GoTo skipVMP +dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart +SET $STATUS_VIRTUALMACHINEPLATFORM=Done +:skipVMP +::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + +CALL :banner +CALL :HUD + +IF EXIST "%$LOGPATH%\var\Part-I-Reboot.txt" (SET $STATUS_REBOOT=Check) && GoTo skipReboot +echo WSL Setup reboot: %DATE% %TIME% > "%$LOGPATH%\var\Part-I-Reboot.txt" +SET $STATUS_REBOOT=Rebooting +shutdown /r /t 10 /c "WSL Setup" /d p:2:4 +echo. +CALL :banner +CALL :HUD +echo. +PAUSE +:skipReboot +::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + + +:PartII +CALL :banner +CALL :HUD +echo. +cd %PUBLIC%\Downloads +IF EXIST "%$LOGPATH%\wsl_update_x64.log" SET $STATUS_WSL_KERNEL_UPDATE=Check +IF EXIST "%PUBLIC%\Downloads\wsl_update_x64.msi" GoTo skipWSLKU +:: wmic product GET name /VALUE | FIND /I "Name=Windows Subsystem for Linux Update" +echo Use WGET or CURL to download WSL Kernel Update? +Choice /c WC /m "[W]GET or [C]URL": + IF %ERRORLEVEL% EQU 2 GoTo subCURL + IF %ERRORLEVEL% EQU 1 GoTo subWGET + +:subCURL +echo. +curl -V 2> nul > "%$LOGPATH%\var\CURL_VERSION.txt" +curl https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi > %PUBLIC%\Downloads\wsl_update_x64.msi +wsl_update_x64.msi /passive /q /norestart /log "%$LOGPATH%\wsl_update_x64.log" +GoTo skipWSLKU + +:subWGET +echo. +wget -V 2> nul > "%$LOGPATH%\var\WGET_VERSION.txt" +IF %ERRORLEVEL% NEQ 0 GoTo errWGET +IF NOT EXIST "wsl_update_x64.msi" wget "https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi" +wsl_update_x64.msi /passive /q /norestart /log "%$LOGPATH%\wsl_update_x64.log" +SET $STATUS_WSL_KERNEL_UPDATE=Done + +:skipWSLKU +::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + +:Conf +CALL :banner +CALL :HUD + +wsl --set-default-version 2 +SET $STATUS_WSL_DEFAULT_VERSION=Done +echo WSL Setup Part-II: %DATE% %TIME% > "%$LOGPATH%\var\Part-II-Complete.txt" +IF EXIST "%$LOGPATH%\var\Part-II-Complete.txt" echo WSL Setup completed: %DATE% %TIME% > "%$LOGPATH%\WSL-Setup_Complete.txt" +::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + +:: jump Error section +GoTo end +::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + +:errWGET +color 4E +echo WGET missing! +echo. +echo Install WGET from chocolatey repository? +Choice /c YN /m "[Y]es or [N]o": + IF %ERRORLEVEL% EQU 2 GoTo end + IF %ERRORLEVEL% EQU 1 GoTo WGET_I +:WGET_I +choco install wget /Y +GoTo PartII +::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + + + +:End +IF EXIST "%$LOGPATH%\WSL-Setup_Complete.txt" IF %$DEGUB_MODE% EQU 0 RD /S /Q "%$LOGPATH%\var" +CALL :banner +CALL :HUD +echo. +IF EXIST "%$LOGPATH%\WSL-Setup_Complete.txt" echo WSL Setup Completed! +IF NOT EXIST "%$LOGPATH%\WSL-Setup_Complete.txt" echo WSL Setup is not complete! +echo. +timeout /t 60 +exit