WSL allows you to set launch configurations on all distribution packages independently using a file located at /etc/wsl.conf
, whenever WSL is launched this configuration is applied automatically. This configuration file follows the INI file format, which is a standard for configuration files for software, with a basic structure composed of sections
, properties
and values
saved in a text file. In case this file doesn’t exist you can also create one yourself.
Windows Subsystem for Linux will detect and parse this file at the launch to obtain the configuration settings which come under 3 of the following categories also known as Sections
:
[automount]
Section
As the name suggests, this section would control how you mount various file systems on your distribution automatically at the launch.
Property | Value | Default | Description |
---|---|---|---|
enabled | boolean | true |
When set to true , auto mounts fixed drives such as C:/ or D:/ with DrvFs under directory /mnt . |
mountFsTab | boolean | true |
When set to true , auto mounts the files systems like SMB share declared in the /etc/fstab file. |
root | String | /mnt/ |
Specify the default mount location of your fixed drives, that means if we declare /test/ as the value of root property then, my fixed drive would be mounted as /test/c , /test/d and so on. |
options | comma-separated list | empty string | This value is appended to the default DrvFs mount options string |
Let’s suppose that, we want to mount our fixed drives with drvfs
on a folder other than /mnt/
, then we can define that under root
property as a value, for example /test/
in the /etc/wsl.conf
file.
Fixed drives are automatically mounted on the next launch of the distribution. Please note that it is observed that changes may not take effect unless you restart the lxssManager
service on Windows, or terminate and relaunch the distro.
[network]
Section
Network section of WSL configuration files provides 2 properties that can be used to tweak, the name resolution and how host files are configured on your Windows Subsystem for Linux.
Property | Value | Default | Description |
---|---|---|---|
generateHosts | boolean | true | When set to true it automatically generates /etc/hosts with the host to IP address mappings from Windows hosts file: %WINDIR%\System32\drivers\etc\hosts . |
generateResolvConf | boolean | true | When set to true it automatically generates /etc/resolv.conf file with a list of Domain Name Servers for name resolution process to work on WSL, |
To demonstrate one of these properties, I have disabled the generateResolvConf
property by setting it to false
in wsl.conf
file, as shown in step-1 of the below screenshot. Now, if I try to ping any website (step-2) it fails to resolve any hostnames to their respective IP addresses, because no name server would be there to facilitate the name resolution. So I’ve to enable that setting again like in step-3 and terminate my WSL distro (step-4) for configuration changes to apply.
After making the changes when the distro is relaunched, you will observe that /etc/resolv.conf
is automatically generated with name servers. Now as demonstrated in the below screenshot, if you send ICMP requests to a website then the name resolution will work and you will start receiving response packets from the target IP address.
[interop]
Section
This section of the wsl.conf
file deals with 2 important settings for Windows-Linux interoperability, which are the following:
Property | Value | Default | Description |
---|---|---|---|
enabled | boolean | true | When set to True WSL distro will launch Windows processes, like Notepad.exe , otherwise not |
appendWindowsPath | boolean | true | When set to True , WSL will append Windows path elements to the Distribution’s environment variable $PATH . |
In the following example, if enabled
property is set to false
then WSL will not support any Windows processes like Notepad.exe
to be executed from Linux. As demonstrated in the screenshot in step-1, bash
can’t find the notepad executable and throws an error. To resolve this roll back the value of property enabled
to true
and restart your distro to make Windows processes work again.
Similarly, when you disable the appendWindowsPath
property by setting it to false
, then elements of Windows PATH
variable is not appended to the Linux $PATH
environment variable. As demonstrated in the following screenshot, in step-4, when the appendWindowsPath
is set to true
and the distro is terminated and relaunched, then values in Windows PATH
variable starts to appear in the Linux $PATH
environment variable.
~ Author of “PowerShell Guide to Python“, and currently writing a Book on “Windows Subsystem for Linux (WSL)“
All my books are available as a discounted bundle:
-
- PowerShell Guide to Python : This PowerShell Scripting guide to Python is designed to make readers familiar with syntax, semantics and core concepts of Python language, in an approach that readers can totally relate with the concepts of PowerShell already in their arsenal, to learn Python fast and effectively, such that it sticks with readers for longer time.
- Windows Subsystem for Linux (WSL) : Keywords, definitions, and problems WSL solve and how it works under the hoods. From download to setup to interoperability this book even covers details like the architecture of Windows subsystem for Linux and new features in WSL 2 with some wonderful use cases.
Prateek Singh
Related posts
Categories
Author of Books
Awards
Open Sourced Projects
Author at
Blog Roll
Mike F RobbinsDamien Van Robaeys
Stéphane van Gulick
Kevin Marquette
Adam Bertram
Stephanos Constantinou
Francois-Xavier Cat
Ravikanth Chaganti
Roman Levchenko
Blog Stats
- 1,132,211 People Reached