Skip to content

WSL Config

Shamik edited this page Mar 11, 2022 · 6 revisions

WSL Config

There are two options for configuring a WSL system with custom resources i.e. # of CPUs, memory(RAM), Swap,...

  1. .wslconfig
  2. 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.

.wslconfig

  • Stored in the %UserProfile% directory; i.e. C:\Users\<UserName>
    • Neat trick to get to your %UserProfile% is to cd ~ in powershell, which typically will return your home directory/%UserProfile%
    • The final directory path would look like C:\Users\<UserName>\.wslconfig
  • 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 or nano .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.
WSLConfig

  • 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

wsl.conf (Retrieved from Microsoft Docs)

  • 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 by cd / (goes to the root directory) and then cd /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

Clone this wiki locally