• +43 660 1453541
  • contact@germaniumhq.com

Essential Windows Subsystem for Linux (WSL) Settings


Essential Windows Subsystem for Linux (WSL) Settings

As an alternative to cygwin, I’m using more and more the Windows Subsystem for Linux (WSL). Unfortunately when trying to use it, esp. if coming from cygwin you’ll need to consider the filesystem permissions, and how the drives are mounted so docker plays well when doing volume mounts. Here’s how:

git: Ensuring filesystem changes aren’t falsely reported

For some reason the default umask in WSL is 000. Umask specifies the permissions that are set on newly created files, using a bit masking. For our 000 value it means every folder and file have 777 as mode when created (read/write/exec for everyone?!). Doing a git clone instantly sees that all the file modes have changed.

So we need to start with the basics. First we’ll change the umask to 022:

umask 022

If you’re using both cygwin and WSL, you’ll want to also stop the tracking of the filesystem mode altogether, since they reset each other:

git config --global core.filemode false

Then on each repository, you need to change the .git/config and delete the filemode attribute from the [core] section, since by default on clone it’s true regardless of your global setting.

Docker Integration

In here, in the desktop version you need only two things:

  1. In the Docker UI, in "General", "Expose daemon on tcp://localhost:2375 without TLS"

  2. In "Shared Drivers" mark the "C" volume. For this to work, you need to create the /etc/wsl.conf file inside the WSL:

[automount]
root=/
options="metadata"

This ensures drive mounts happen in / instead of /mnt inside WLS. That means you’ll have /c, and not /mnt/c like the default. That allows for volume mounts to work as expected, since in docker in Windows drives are mounted as /c/, /d/, etc. for C:\, D:\ respectively.

Metadata allows for having file permissions, on the NTFS mount, like I was mentioning in the git section.

That means when inside a folder in a mounted drive you are able to do:

docker run -it --rm -v `pwd`:`pwd` ubuntu:18.04

and you’ll have the correct mounts.

Conclusion

Despite the tedious workarounding having WSL over cygwin is a fantastic productivity boost. I’m finally able to use node, python and even java that are built natively for Linux.