What is Windows Subsystem for Linux 2?

Windows Terminal 1 hero

At its annual Build conference in Seattle this week, Microsoft announced version 2 of the Windows Subsystem for Linux (WSL) along with Windows Terminal, a new terminal for Windows 10. You can read more about the announcement here. WSL has proved popular with developers and administrators that work with Windows and Linux. Microsoft is continuing to invest in WSL to make it as easy as possible for IT professionals to work with Linux without needing to use a Linux desktop.

What is the Windows Subsystem for Linux?

If you’re a developer or system administrator that needs to compile Linux binaries or use Linux tools, then the Windows Subsystem for Linux (WSL) is for you. WSL primarily makes it easier for developers to work with Linux in Windows. WSL 1 isn’t based on virtual machines or containers but instead it provides an emulation layer that maps Windows kernel system calls to Linux kernel system calls, allowing Linux binaries to run in Windows unmodified. WSL also maps Windows services, like the filesystem and networking, as devices that Linux can access. WSL isn’t intended for users that want to spin up their favorite Linux apps, but it is a tool for developers and sysadmins that need Linux interoperability in Windows.

Instead of using a VM or container, WSL 1 virtualizes a Linux kernel interface on top of the Windows kernel. This means that running WSL only requires a minimal amount of RAM. And when not in use, the WSL driver isn’t loaded into memory, making it more efficient than a solution based on a VM or container. Users can then load a Linux distribution from the Microsoft Store and use it like an application on their PC. Windows 10 supports installing multiple Linux distributions side-by-side. For more information on installing WSL and a Linux distribution in Windows 10, check out How to Install Windows Subsystem for Linux on Petri.

What is Changing in Windows Subsystem for Linux 2?

WSL 1 is a popular Windows 10 feature, but it does suffer from slow disk I/O and it has limited support for Linux apps. To address these issues, WSL 2 introduces a new architecture that changes how Linux binaries interact with Windows and hardware devices without changing the user experience that you’re familiar with in WSL 1.

In short, WSL 2 uses a real Linux kernel to overcome the limitations of WSL 1. Users will be able to run Linux either as WSL 1 or WSL 2 distributions or run WSL 1 and WSL 2 distributions side-by-side. Microsoft also says that you will be able to upgrade and downgrade distributions at any time.

Microsoft Linux Kernel in Windows

Microsoft is rolling its own Linux kernel for use with WSL, making full system call compatibility a reality. The kernel shipped with Windows 10 will be based on the latest stable Linux kernel release, starting with kernel 4.19, and it will be updated via Windows Update as new stable versions of the Linux kernel become available. Microsoft has optimized the kernel for use with WSL 2 for the best experience, ensuring that it is small and performant. And not only that but Microsoft is making their WSL Linux kernel open source and available on GitHub.

Architectural Changes in Windows Subsystem for Linux 2

One of the reasons to use WSL 1 was to avoid the overhead of running Linux in a VM. But WSL 2 will run the Linux kernel in a virtual machine (VM). So what gives? Microsoft is using a lightweight utility VM that rather than isolating the Linux kernel from Windows and consuming a lot of resources like a traditional VM, instead provides high levels of integration, fast startup times, and a small resource footprint. Additionally, this all happens transparently to the end user with no need to manage a VM.

Microsoft claims that WSL 2 Linux distributions start in less than 2 seconds and can run services and apps straight away. Disk I/O is also much faster. Microsoft says that disk I/0 can be up to 20 times faster depending on the application and how it is interacting with the file system. For example, decompressing a tarball file is 20 times faster than WSL 1 and between 2 and 5 times faster with git clone, npm install, and cmake.

Because WSL 2 no longer uses emulation to translate Linux system calls, it is compatible with a wider range of applications. Now you could for example run Docker for Linux and FUSE in WSL. Using a real kernel means that Microsoft can introduce changes faster as there’s no need to update the translation layer as new features are added to the Linux kernel.

When Can I Get Windows Subsystem for Linux 2?

Now you understand how WSL 2 works, what about actually getting your hands on it? WSL 2 will be available as part of the Windows Insider program before the end of June 2019. That means until the next feature release of Windows 10, which is due in fall 2019, you’ll need to be on an Insider build to use WSL. That’s assuming WSL 2 is scheduled to appear in Windows 10 19H2. But it looks like work on WSL 2 is already reasonably far along, so it could be ready for general availability in the second half of 2019.

Related Article: