Skip to content

Instantly share code, notes, and snippets.

@ViniciusFXavier
Last active July 5, 2024 14:43
Show Gist options
  • Save ViniciusFXavier/86ec35a2a181a5cd8d6a751b0deb552a to your computer and use it in GitHub Desktop.
Save ViniciusFXavier/86ec35a2a181a5cd8d6a751b0deb552a to your computer and use it in GitHub Desktop.
Install and configure WSL
# Doc: https://learn.microsoft.com/en-us/windows/wsl/wsl-config
# Settings apply across all Linux distros running on WSL 2
[wsl2]
# Limits VM memory to use no more than 10 GB, this can be set as whole numbers using GB or MB
memory=10GB
# Sets the VM to use two virtual processors
processors=2
# Sets amount of swap storage space to 10GB, default is 25% of available RAM
swap=10GB
# Turns off output console showing contents of dmesg when opening a WSL 2 distro for debugging
debugConsole=false

To enable Windows Subsystem for Linux (WSL), the correct command would be:

.\Dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux

For Virtual Machine Platform, use:

.\Dism.exe /online /enable-feature /featurename:VirtualMachinePlatform

And for Hyper-V, the command is:

.\Dism.exe /online /enable-feature /featurename:Microsoft-Hyper-V -All

Remember to run PowerShell as an administrator to perform these operations.

@echo off
net session >nul 2>&1
if %errorLevel% == 0 (
powershell -Command "Add-Type -AssemblyName PresentationFramework; if((gsv wslservice).StartType -eq 'Automatic') { $choice = [System.Windows.MessageBox]::Show('Disable WSL and Restart?', 'Version Choice', 'OKCancel', 'Information', 'Cancel');if ($choice -eq 'OK') {Set-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Services\WslService -Name Start -Value 0x00000004; Restart-Computer}} else { $choice = [System.Windows.MessageBox]::Show('Enable WSL and Restart?', 'Version Choice', 'OKCancel', 'Information', 'Cancel');if ($choice -eq 'OK') {Set-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Services\WslService -Name Start -Value 0x00000002; Restart-Computer}};"
) else (
echo "Right-Click Bat File And Run As Administrator."
)
pause
:: 0x00000000 = Boot
:: 0x00000001 = System
:: 0x00000002 = Automatic
:: 0x00000003 = Manual
:: 0x00000004 = Disabled
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment