-
Notifications
You must be signed in to change notification settings - Fork 0
WSL Config
There are two options for configuring a WSL system with custom resources i.e. # of CPUs, memory(RAM), Swap,...
- .wslconfig
- wsl.conf
.wslconfig is used to configure settings globally across all installed distributions running on WSL 2.
On the other hand, wsl.conf is used to to configure settings per-distribution for Linux distros running on WSL 1 or WSL 2.
- Stored in the
%UserProfile%
directory; i.e.C:\Users\<UserName>
- Neat trick to get to your
%UserProfile%
is tocd ~
in powershell, which typically will return your home directory/%UserProfile%
- The final directory path would look like
C:\Users\<UserName>\.wslconfig
- Neat trick to get to your
- Will work only for WSL 2
- Create a .wslconfig in windows by opening Notepad and saving the file name as .wslconfig
- Create a .wslconfig in bash by either typing
vim .wslconfig
ornano .wslconfig
- Type the following in the .wslconfig file
[wsl2]
# kernel=C:\\temp\\myCustomKernel
memory=5GB # Limits VM memory in WSL 2 to 5 GB
processors=5 # Makes the WSL 2 VM use two virtual processors
The WSL resources are restricted to 5GB of memory and 5 processors
- Save the file and close it
- Stop all instances of WSL by running
wsl --shutdown
- Wait for the 8 second rule for the new configuration settings to appear, if you launch WSL immediately the new configuration settings won't appear
- Restart WSL
Upon successful configuration one can check the custom resources by typing htop
and viewing the # of processors and memory allocation. Below is an image of the same.
- A basic example of the .wslconfig file limiting the WSL resources to 5GB of memory and 5 processors is here
- For a more detailed configurability through .wslconfig refer here
- Stored in the
/etc
directory of the distribution as a unix file - Used to configure settings on a per-distribution basis. Settings configured in this file will only be applied to the specific Linux distribution that contains the directory where this file is stored
- Can be used for distributions run by either version, WSL 1 or WSL 2
- Navigate to
/etc
directory bycd /
(goes to the root directory) and thencd /etc
- The wsl.conf file must be placed here
The above wsl.conf instructions are here
The wsl.conf file gives one the ability to configure a lot of setting and more details can be found here
sudo dpkg-reconfigure ca-certificates
lscpu
wsl -l -o
wsl –l -v
wsl --install -d <distribution name>
wsl --unregister <distribution name>
ubuntu config --default-user root
ubuntu config --default-user <username>
su -
wsl -s Ubuntu-20.04
lsb_release –a
free -h
sudo sh -c "echo 3 > /proc/sys/vm/drop_caches"
If the above doesn't work
- STEP 1
alias drop_cache="sudo sh -c \"echo 3 >'/proc/sys/vm/drop_caches' && swapoff -a && swapon -a && printf '\n%s\n' 'Ram-cache and Swap Cleared'\""
- STEP 2
source ~/.bashrc
- STEP 3
drop_cache
sudo apt update
sudo apt install -y wget apt-transport-https software-properties-common
wget -q https://packages.microsoft.com/config/ubuntu/$VERSION_ID/packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb
sudo apt update
sudo get install -y powershell
pwsh
mv ~/.vscode-server ~/.vscode-server-bkup
# Restart VScode in WSL
rm -rf ~/.vscode-server/extensions/
mv ~/.vscode-server-bkup/extensions/ ~/.vscode-server/extensions/