DEV Community

loading...
Cover image for An Introduction to WSL

An Introduction to WSL

Dave Howson
Software Engineer from Sri Lanka ☀️ Interested in Web Development ☁️ Machine Learning ⌛️ Data Analysis 🧾
・5 min read

What is WSL?

Introduced with the Anniversary Update in August 2016, the Windows Subsystem for Linux is a feature that lets you work seamlessly on a Linux environment inside of Microsoft Windows.
WSL is a compatibility layer that runs on top of a Windows environment letting you experience the best of both worlds.
Unix based Systems like Linux and macOS have always been the go-to Operating Systems for Web Developers and Open Source project contributors due to their unparalleled support for development tools and their similarity to production environments. Microsoft Windows has improved its developer experience tremendously over the years, especially with the introduction of tools like PowerShell and Hypervisor technologies, but many developers still prefer Linux over Microsoft Windows when it comes to their development platform.
However, WSL is here to change that. When combined with the convenience of Windows and the functionality of Linux, WSL becomes the obvious platform of choice for many developers especially in the field of Web Application Development.

WSL1 vs WSL2

WSL comes in two versions and they have significantly different architectures under the hood. In order to understand the architecture of WSL, we must first understand the architecture of the Linux Operating System. A machine that runs on Linux can basically be divided into four sections.

  1. Hardware - This is the physical machine
  2. Kernel - This is the core of the Linux operating system. It facilitates the communication between software and hardware.
  3. Shell - This is the interface that takes input from the user and communicates this with the kernel
  4. Applications and Utilities

Architecure of Linux

WSL1 runs Linux compatible applications and utilities on top of a Linux Shell (e.g. Bash). In a Linux Operating System, the Linux Shell communicates with the Linux Kernel in order to process and relay system calls sent from applications and user commands. However, in WSL1, a Linux Kernel does not exist. Instead, system calls from the Shell are translated to calls that are compatible with the Windows NT Kernel that ships with Microsoft Windows.

Processes in an operating system execute in one of two modes. Lower level processes that need direct access to the Kernel and hardware devices are executed in the Kernel Mode while higher level processes are executed in the User Mode. When a higher level process makes a lower level system call, this is relayed to a process running in the Kernel Mode which handles this call and replies accordingly. In WSL1, Unmodified Linux Binaries run inside processes known as Pico Processes in the User Mode. These Pico Processes run in isolated environments and they do not have any direct contact with the outside environment. System calls sent out by Pico Processes are handled by Pico Drivers. Due to the isolated architecture of these processes, they are able to run pure Linux binaries without having to worry about the environment in which they are executed in.
WSL1 consists of two Pico drivers - LXCore & LXSS. All system calls sent out by Pico Processes are handled by these two drivers. These drivers, running in the Kernel Mode, translate Linux system calls to Windows system calls that can be understood by the Windows NT Kernel. This allows pure Linux binaries running on top of a WSL environment to function as if they are functioning in a pure Linux environment without having to bother about the underlying Windows Operating System.

This translation based architecture was a good solution to implement interoperability between Windows and Linux. But translation takes time and some Linux calls cannot be translated perfectly to Windows calls. Instead, the WSL team came up with a better solution in WSL2.

WSL2 boots up a Linux Kernel inside a highly optimized Virtual Machine which uses the Hyper-V architecture of Windows. WSL2 provides all the features of WSL1 along with some major improvements such as

  • Full System Call Compatibility
  • Faster IO Performance
  • Smaller Memory Footprint

Since WSL2 is based on virtualization via the Hyper-V architecture, it is able to provide users with a complete Linux Kernel. This Kernel runs separately alongside the NT Kernel and all hardware calls are handled by the underlying Hypervisor.

WSL2 Architecture

The Highly Optimized Utility VM that WSL2 runs on top of gives it the ability to boot up extremely faster than a traditional VM. Similar to WSL1, WSL2 can easily access the Windows File system and other IO components such as external devices and network connectivity. In fact, the modern architecture of WSL2 ensures that it is much faster than WSL1 when it comes to accessing files and networks.
Since WSL2 has access to a fully fledged Linux Kernel, it provides users with 100% system call compatibility. This means that WSL users can do anything that native Linux users can do with their Kernel.
The inclusion of a Linux Kernel also means that WSL2 can receive updates much more efficiently than WSL1. Previously, in WSL1, when a new feature or an update is deployed to the Linux Kernel, the WSL team had a lot of work to do in the translation layer before this feature was deployed to WSL users. However, in WSL2, new Linux Kernel features and updates can simply be deployed via Windows updates since there is no translation layer, giving WSL users access to the latest and greatest Linux features in an instant.

Why use WSL?

WSL is the perfect combination for Developers of Web and Open Source Projects who can benefit from the combined power of Windows and Linux. Since most web servers run on Linux environments, developers can develop their applications on production-like environments while enjoying the accessibility, stability and modernness of Windows. WSL allows developers to run Linux specific tools in a Windows environment without having to go through the hassle of running a Virtual Machine. Unlike traditional VM's, WSL is fast, efficient and needs no initial configuration to get it up and running. WSL provides developers with an advanced, state-of-the-art Linux experience on Windows without any of the complexity. Developers do not have to resort to dual boot or VM's anymore in order to experience the best of both worlds, making WSL the perfect choice for them.

Linux has always stood out over the rest of the Operating Systems out their because of its impressive list of distributions. WSL supports almost all of the popular Linux distros and they can be easily downloaded via the Microsoft Store. WSL users can install multiple Linux distros and seamlessly switch between them when needed.

The WSL team has gone above and beyond to make WSL a worthwhile option for developers. Unlike in VM's where the virtualized OS is isolated from the environment around it, WSL has full access to the underlying systems network and files, making it very easy for developers to work on the same projects in both Windows and Linux environments. Microsoft has also released plugins for tools such as VSCode that help developers access projects inside WSL via the VSCode UI, which simplifies cross platform development workflows. Developers can simply open VSCode inside Windows, open up their projects inside WSL and start coding right away. No hassle, no configuration and no stress!

WSL props up Microsoft Windows as a serious candidate in the developer Operating System market. With an ambitious and dedicated team behind the development of WSL, Microsoft has opened up new possibilities in the world of remote development and we couldn't be more happier about this.

For more information about WSL and how to get started on it, visit the Official WSL Docs.

Discussion (0)