You are currently viewing Understanding differences between WSL 1 and WSL 2

Understanding differences between WSL 1 and WSL 2

We have seen how the WSL can be installed on Windows 10 in the previous article. We also have discussed that there are two major versions of WSL, viz., WSL 1 and WSL 2.

In this article, let’s try to see a bit about how WSL 1 is different from WSL 2.

WSL 1

WSL 1 was released almost 4 years back and since then it is evolving. So, how was WSL 1 working.

The concept was still the same, it was about running Linux binary executable, but in WSL 1, there was no Linux Kernel.

So how was it working ?

There was a translation layer between Linux distribution and Windows Kernel. This translation layer was responsible to handle all the kernel level operations, translate them to the instructions which windows kernel can understand. Once the windows kernel would perform execution and would return the results to WSL translation layer.

WSL 1: Basic Architecture

So Linux distribution was never aware that it was Windows kernel which was handling all the requests.

If any requests came to windows kernel which it could not handle, there was a fallback logic to run commands in windows environment. e.g. if you fire notepad.exe from the Linux prompt, it would open Notepad program from Windows.

Issues

So the whole logic of running Linux binaries was working because of translation layer and ultimately Windows kernel was executing the commands. This setup also had some issues which could not be addressed very easily.

e.g. Let’s say there is a directory with name “DIR” and it has a file foo.txt. Now let’s say if you open foo.txt in notepad. While the file is open, you try to rename the DIR directory to some other name. What would happen ? Windows would not allow it.

It would throw error saying some programs are using the directory so you are not allowed to perform this operation. But if you follow same steps on Linux machine, it would allow it.

There are many such differences because of very fundamental design decisions which were taken while developing respective kernels. Those decisions cannot be easily changed now as it would certainly break some or the other thing.

Although this translation layer of WSL 1 was performing the translations instantaneously there were obviously some clock cycles consumed by it and hence, there was a thought that it could further be made more efficient.

WSL 2

The WSL 2 changed the fundamental approach to solve the problem. Instead of having a translation layer, it brought a full Linux kernel in the picture. How is it possible to run two kernels ?

There comes the concept of Lightweight utility virtual machine. This is very tiny virtual machine which starts within 1 second and consumes very less amount of compute. This virtual machine is installed as soon as you install the optional feature Windows Subsystem for Linux on Windows.

WSL 2: Basic Architecture

Also there is a Linux kernel now in WSL 2. And as you can see in the ao This is special kernel that is fully tuned for WSL 2 and fully managed by Microsoft. It is also open source.

So, in WSL 2, when a binary program issues an instruction it is not translated. It is rather handed over to the Linux kernel. Any command which cannot be handled by Linux kernel is handed over to Windows.

Does it mean that there are no limitations ? Certainly not.

As of today, the Linux distribution in WSL is not able to run the Linux GUI applications YET. But considering the amount of efforts being put by Microsoft in this, it may be on their agenda and may come soon in future WSL release.

This article is based on the information from Microsoft Ignite session. You can refer it for more details. I hope this article was informative. Let me know your thoughts.

Leave a Reply Cancel reply