WSL

Microsoft recently released a new feature for the Windows Subsystem for Linux version 2 (WSL2) that allows you to configure global options that will be used by all WSL2 Linux distributions installed in Windows 10.

This is done through a configuration file named .wslconfig that will need to be created in a user's %UserProfile% folder. 

As all WSL2 distributions are run under the same virtual machine instance, once a global configuration file is created, it will be used for all WSL2 distros installeed in Windows 10. Linux distros running under WSL1 will not be affected by this config file.

To see a list a installed WSL2 distros installed on a machine that would be affected by a global configuration file, you can type the wsl -l -v command. For more information on how to upgrade a WSL distro to WSL2, you can see this article.

How to create a global configuration file for WSL2

To create a global configuration for all installed WSL2 Linux disributions, create a file named .wslconfig in your user profile folder.

For example, if your Windows 10 user name is Bleeping, then you would create the file at C:\users\Bleeping\.wslconfig.

The current options and format that can be used in a global configuration file are:

[wsl2]
kernel=              # An absolute Windows path to a custom Linux kernel.
memory=              # How much memory to assign to the WSL2 VM.
processors=        # How many processors to assign to the WSL2 VM.
swap=                # How much swap space to add to the WSL2 VM. 0 for no swap file.
swapFile=            # An absolute Windows path to the swap vhd.
localhostForwarding= # Boolean specifying if ports bound to wildcard or localhost in the WSL2 VM should be connectable from the host via localhost:port (default true).

#  entries must be absolute Windows paths with escaped backslashes, for example C:\\Users\\Ben\\kernel
#  entries must be size followed by unit, for example 8GB or 512MB

So for example, if we wanted your WSL2 distros to use 5GB of memory and 3 processors, you would create a .wslconfig file that looks like the following. When creating the file, due to a bug it is important to not have any whitespace after an option's value.

.wslconfig Global Configuration File
.wslconfig Global Configuration File

Once you save the .wslconfig file, you will need to shutdown the distro by using the wsl.exe --shutdown [distro_name] for the changes to go into effect.  Before doing so, make sure all of your work is saved.

Once you shutdown and start the Linux distro again, you will find that it is now using your specified configuration options.

Ubuntu running with 5GB of Memory
Ubuntu running with 5GB of Memory and 3 CPUs

You can now use a custom Linux kernel

One of the more interesting features that you can configure as a global option is the ability to specify a custom Linux kernel to use with your installed distros.

As part of the WSL2 release, Microsoft has also made their Linux kernel available on GitHub. If users want to customize the kernel to include a particular module or patch, they can recompile it and specify to use that kernel instead.

To do this, compile a custom kernel, save it somewhere in Windows 10, and then use the kernel= option to specify the full path to the kernel.

After restarting the Linux distro, WSL2 will use that customized kernel.

Related Articles:

Windows 10 KB5035941 update released with lock screen widgets

Microsoft Is Showing Inline Ads in their Windows 10 Mail App Message List

Windows 10 KB5001716 update fails with 0x80070643 errors, how to fix

Windows 10 KB5034843 update released with 9 new changes, fixes

Windows 10 KB5034763 update released with new fixes, changes