Image from BleepingComputer

Introduction

Just over a day ago, WSL 2 was released to Windows Insiders in the Fast Ring. Half a year ago or so, I switched to MacOS because I was tired of not having a good Linux experience on Windows. Well Microsoft has heard the cries of Linux lovers, and are shipping with an actual, full fledged Linux kernel now!

Usability & Setup

Before even getting started, of course WSL 2 had to be set up. To my suprise, it was incredibly simple to do. Download my preferred distro from the Windows Store (Ubuntu in this case), enter a few commands in powershell, and things were up and running. I won’t go into detail about installation, seeing as how there’s a really great guide to that right here.

Now that things have been set up, I wanted to make some configurations to the shell, so I could feel at home. Lucky for me I’ve spent some time making an installation script for my config files, that’s been tested on both MacOS and Ubuntu when I made it. It was when I ran that, that it really dawned on me, that Windows now has an actual Linux kernel. No errors or anything. It just worked!

My next step was the real test of strength; Docker. I had seen the demos where they run Docker flawlessly, but I wanted to see it for myself before I believed it. Installed like I would otherwise on any other Ubuntu system. No trickery involved, Docker worked almost flawlessly. Tried a few different images, and they spun up just as quick as they do on my Macbook Pro.

You may have noticed I wrote ‘almost flawlessly’. One weird problem I ran into, was that I couldn’t curl my Nginx container at first. I had to put the container on the host network, in order for it to work. You can see the issue here.

Networking

All in all, it seems that networking is one of the places that can definitely be improved. I won’t in any way say that it doesn’t work; there are just some minor quirks. One major change from WSL 1 to WSL 2, is that it is now a completely separate Virtual Machine. Took me a little time to figure out why I couldn’t just use localhost, when I wanted to connect to my X server. Turns out that WSL is now running with a host-only network adapter.

At first I expected to start a container in WSL on port 80, and then open chrome, type in ‘http://localhost’ and access that container. Instead I had to type in the actual ip (found by ip addr ) in chrome, in order to access the container. This isn’t a problem in and of itself, however it would be nice to have the ability to choose, how you want the container to be networked.

NOTE: Since this article was written, the WSL has updated this. While the WSL VM is still on a host-only network adapter, you can access things like docker containers through localhost on your Windows (host) machine

Ping

One of the things that I can’t figure out, is why my ping sometimes won’t work. If I try to ping 8.8.8.8 from WSL 2, it works fine. However when I then try to ping some device on my home network, it fails 100% of the time. That’s not to say that I can’t connect to any of the devices. I can control my IoT devices. I can setup an X Server on my host and run things like gedit. Only catch there is that I have to export DISPLAY=<ip-of-host>:0.0 , instead of export DISPLAY=:0 like I was used to.

UPDATE: Personally I no longer experience issues with ping

Accessing WSL by IP

As mentioned, if you want to access any containers you have running on WSL, you have to access it by the ip. I quickly grew tired of this, and found a little workaround. Inside C:\Windows\System32\drivers\etc, you can edit the hosts file, and add the following line:

<ip-of-wsl> wsl

Now you can simply type http://wsl in your browser, and access it that way.

File Performance

Probably one of the biggest hurdles in WSL 1 was file performance. Because WSL was ‘simply’ a translation layer for system calls, something like git clone and yarn install could take an eternity. You may have heard that this has been severely improved in WSL 2, and the rumors are true!

Because WSL is now running as a VM, it is utilising an actual ext4 file system. Yes, this means that there are no translation layers, no magic or anything. Just raw powerful file performance in Linux; but there’s a catch. This is only when you are manipulating Linux files on Linux. Below you can see the incredibly unscientific benchmark I ran: