e.v.o
Forum Noob
Since the Windows version 2004 feature update is available i encourage you all to update your dev pcs to that version.
In this post i am going to address the process in upgrading your WSL 1 distribution to WSL 2 and how to gain a performance boost using a custom .wslconfig (%USERPROFILE%\.wslconfig). Just copy/paste the commands listed below and you are good to go. This will also greatly improve your Docker performance.
If you have questions, comments or just want to rant about this post then feel free to do so.
In this post i am going to address the process in upgrading your WSL 1 distribution to WSL 2 and how to gain a performance boost using a custom .wslconfig (%USERPROFILE%\.wslconfig). Just copy/paste the commands listed below and you are good to go. This will also greatly improve your Docker performance.
If you have questions, comments or just want to rant about this post then feel free to do so.
- Enable the "Virtual Machine Platform" optional feature
Open PowerShell as Administrator and run:
Code:dism /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart - Restart your system
- Install Linux kernel update package
Open PowerShell as Administrator and run:
Code:Invoke-WebRequest -Uri 'https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi' -OutFile "$env:TEMP\wsl_update_x64.msi" Start-Process msiexec.exe -Wait -ArgumentList '/I %TEMP%\wsl_update_x64.msi /quiet' wsl --set-default-version 2
What it does:
Download the Linux kernel update package
Install Linux kernel update package on your machine for use with WSL 2
Set WSL 2 as your default version for new linux distributions
- Convert your existing distribution(s) to WSL 2
Open PowerShell as Administrator and run:
Code:wsl --shutdown wsl --list --verbose wsl --set-version NAME 2 # Replace NAME with one of the listed
What it does:
Shutdown all running wsl instances. Will shutdown every running WSL instance!
List available WSL distributions
Convert the given WSL 1 to WSL 2. This step might take some time.
Example from my machine:
Code:PS C:\Users\Velocet> wsl --list --verbose --all NAME STATE VERSION * Ubuntu-18.04 Running 1 Arch Stopped 2 Ubuntu-20.04 Stopped 1 PS C:\Users\Velocet> wsl --shutdown PS C:\Users\Velocet> wsl --set-version Ubunto-18.04 2 ... PS C:\Users\Velocet> wsl --list --verbose --all NAME STATE VERSION * Ubuntu-18.04 Stopped 2 Arch Stopped 2 Ubuntu-20.04 Stopped 1 - Configure global WSL 2 options with .wslconfig
Code:$wslconfig = '[wsl2] kernelCommandLine=noibrs noibpb nopti nospectre_v1 nospectre_v2 nospec_store_bypass_disable no_stf_barrier spectre_v2_user=noibrs noibpb nopti nospectre_v1 nospectre_v2 nospec_store_bypass_disable no_stf_barrier spectre_v2_user=off spec_store_bypass_disable=off l1tf=off mitigations=off mds=off tsx_async_abort=off spectre_v2=off kvm.nx_huge_pages=off kvm-intel.vmentry_l1d_flush=never ssbd=force-off tsx=on' New-Item -Path "$env:USERPROFILE" -Name '.wslconfig' -ItemType File -Value $wslconfig
What it does:
Create a variable ($wslconfig) with additional kernel command line arguments.
Create .wslconfig in your user profile folder and fill it with the $wslconfig variable. This file configures the global WSL (2) options.
Kernel command line parameters explanation: kernel-parameters.txt
- Additional steps:
- Disable Spectre/Meltdown mitigations on Windows
If you haven't already disabled spectre/meltdown mitigations on Windows i greatly encourage you to do so using InSpectre. There is no sense in crippling the performance of your home computer.
- Add your WSL distribution folder to the Windows Defender/Security exclusion list
How to add an exclusion to Windows Security.
Path to your WSL distribution: %LOCALAPPDATA%\Packages\
Example for Ubuntu-20.04: %LOCALAPPDATA%\Packages\CanonicalGroupLimited.Ubuntu20.04onWindows_79rhkp1fndgsc
- Disable Spectre/Meltdown mitigations on Windows