Windows Subsystem for Linux

Windows Subsystem for Linux (WSL) is a feature of Windows that allows developers to run a Linux environment without the need for a separate virtual machine or dual booting. There are two versions of WSL: WSL 1 and WSL 2. WSL 1 was first released on August 2, 2016, and acts as a compatibility layer for running Linux binary executables (in ELF format) by implementing Linux system calls on the Windows kernel. It is available on Windows 10, Windows 10 LTSB/LTSC, Windows 11, Windows Server 2016, Windows Server 2019 and Windows Server 2022.
In May 2019, WSL 2 was announced, introducing important changes such as a real Linux kernel, through a subset of Hyper-V features. WSL 2 differs from WSL 1 in that WSL 2 runs inside a managed virtual machine that implements the full Linux kernel. As a result, WSL 2 is compatible with more Linux binaries than WSL 1, as not all syscalls were implemented in WSL 1. Since June 2019, WSL 2 is available to Windows 10 customers through the Windows Insider program, including the Home edition. WSL is not available to all Windows 10 users by default. It can be installed either by joining the Windows Insider program or manual install.
History
Microsoft's first foray into achieving Unix-like compatibility on Windows began with the Microsoft POSIX Subsystem, superseded by Windows Services for UNIX via MKS/Interix, which was eventually deprecated with the release of Windows 8.1. The technology behind Windows Subsystem for Linux originated in the unreleased Project Astoria, which enabled some Android applications to run on Windows 10 Mobile. It was first made available in Windows 10 Insider Preview build 14316.
Whereas Microsoft's previous projects and the third-party Cygwin had focused on creating their own unique Unix-like environments based on the POSIX standard, WSL aims for native Linux compatibility. Instead of wrapping non-native functionality into Win32 system calls as Cygwin did, WSL's initial design (WSL 1) leveraged the NT kernel executive to serve Linux programs as special, isolated minimal processes (known as "pico processes") attached to kernel mode "pico providers" as dedicated system call and exception handlers distinct from that of a vanilla NT process, opting to reutilize existing NT implementations wherever possible.
WSL beta was introduced in Windows 10 version 1607 (Anniversary Update) on August 2, 2016. Only Ubuntu (with Bash as the default shell) was supported. WSL beta was also called "Bash on Ubuntu on Windows" or "Bash on Windows". WSL was no longer beta in Windows 10 version 1709 (Fall Creators Update), released on October 17, 2017. Multiple Linux distributions could be installed and were available for install in the Windows Store.
In 2017 Richard Stallman expressed fears that integrating Linux functionality into Windows will only hinder the development of free software, calling efforts like WSL "a step backward in the campaign for freedom."
Though WSL (via this initial design) was much faster and arguably much more popular than the previous UNIX-on-Windows projects, Windows kernel engineers found difficulty in trying to increase WSL's performance and syscall compatibility by trying to reshape the existing NT kernel to recognize and operate correctly on Linux's API. At a Microsoft Ignite conference in 2018, Microsoft engineers gave a high-level overview of a new "lightweight" Hyper-V VM technology for containerization where a virtualized kernel could make direct use of NT primitives on the host. In 2019, Microsoft announced a completely redesigned WSL architecture (WSL 2) using this lightweight VM technology hosting actual (customized) Linux kernel images, claiming full syscall compatibility. Microsoft announced WSL 2 on May 6, 2019, and it was shipped with Windows 10 version 2004. It was also backported to Windows 10 version 1903 and 1909.
GPU support for WSL 2 to run GPU-accelerated machine learning was introduced in Windows build 20150. GUI support for WSL 2 to run Linux applications with graphical user interfaces (GUIs) was introduced in Windows build 21364. Both of them are shipped in Windows 11.
In April 2021, Microsoft released a Windows 10 test build that also includes the ability to run Linux graphical user interface (GUI) apps using WSL 2 and CBL-Mariner. The Windows Subsystem for Linux GUI (WSLg) was officially released at the Microsoft Build 2021 conference. It is included in Windows 10 Insider build 21364 or later.
Microsoft introduced a Windows Store version of WSL on October 11, 2021, for Windows 11. It reached version 1.0.0 on November 16, 2022 with added support for Windows 10.
Notable releases
Features
WSL is available in Windows Server 2019 and in versions of Windows 10 from version 1607, though only in 64-bit versions.
Microsoft envisages WSL as "primarily a tool for developers – especially web developers and those who work on or with open source projects". In September 2018, Microsoft said that "WSL requires fewer resources (CPU, memory, and storage) than a full virtual machine" (which prior to WSL was the most direct way to run Linux software in a Windows environment), while also allowing users to use Windows apps and Linux tools on the same set of files.
The first release of WSL provides a Linux-compatible kernel interface developed by Microsoft, containing no Linux kernel code, which can then run the user space of a Linux distribution on top of it, such as Ubuntu, openSUSE, SUSE Linux Enterprise Server, Debian and Kali Linux. Such a user space might contain a GNU Bash shell and command language, with native GNU command-line tools (sed, awk, etc.), programming-language interpreters (Ruby, Python, etc.), and even graphical applications (using an X11 server at the host side).
The architecture was redesigned in WSL 2, with a Linux kernel running in a lightweight virtual machine environment.
wsl.exe
The wsl.exe command is used to manage distributions in the Windows Subsystem for Linux on the command-line. It can list available distributions, set a default distribution, and uninstall distributions. The command can also be used to run Linux binaries from the Windows Command Prompt or Windows PowerShell. wsl.exe replaces lxrun.exe which is deprecated as of Windows 10 1803 and later.
WSLg
Windows Subsystem for Linux GUI (WSLg) is built with the purpose of enabling support for running Linux GUI applications (X11 and Wayland) on Windows in a fully integrated desktop experience. WSLg was officially released at the Microsoft Build 2021 conference and is included in Windows 10 Insider build 21364 or later. However, with the introduction of Windows 11, WSLg is finally shipping with a production build of Windows, bringing support for both graphics and audio in WSL apps.
FreeRDP is used to encode all communications going from the RDP Server (in Weston) to the RDP Client (mstsc on Windows) according to the RDP protocol specifications.
Prerequisites for running WSLg include:
Windows 11 or Windows 10 Insider Preview builds 21362-21390.
A system with virtual GPU (vGPU) enabled for WSL is recommended, as it will allow you to benefit from hardware accelerated OpenGL rendering.
Design
WSL 1
LXSS Manager Service is the service in charge of interacting with the subsystem (through the drivers and ), and the way that Bash.exe (not to be confused with the Shells provided by the Linux distributions) launches the Linux processes, as well as handling the Linux system calls and the binary locks during their execution. All Linux processes invoked by a particular user go into a "Linux Instance" (usually, the first invoked process is init). Once all the applications are closed, the instance is closed.
WSL 1's design featured no hardware emulation / virtualization (unlike other projects such as coLinux) and makes direct use of the host file system (through and ) and some parts of the hardware, such as the network, which guarantees interoperability. Web servers for example, can be accessed through the same interfaces and IP addresses configured on the host, and shares the same restrictions on the use of ports that require administrative permissions, or ports already occupied by other applications. There are certain locations (such as system folders) and configurations whose access/modification is restricted, even when running as root, with sudo from the shell. An instance with elevated privileges must be launched in order to get "sudo" to give real root privileges, and allow such access.
WSL 1 is not capable of running all Linux software, such as 32-bit binaries, or those that require specific Linux kernel services not implemented in WSL. Due to a lack of any "real" Linux kernel in WSL 1, kernel modules, such as device drivers, cannot be run. WSL 2, however, makes use of live virtualized Linux kernel instances. It is possible to run some graphical (GUI) applications (such as Mozilla Firefox) by installing an X11 server within the Windows (host) environment (such as VcXsrv or Xming), although not without caveats, such as the lack of audio support (though this can be remedied by installing PulseAudio in Windows in a similar manner to X11) or hardware acceleration (resulting in poor graphics performance). Support for OpenCL and CUDA is also not being implemented currently, although planned for future releases. Microsoft stated WSL was designed for the development of applications, and not for desktop computers or production servers, recommending the use of virtual machines (Hyper-V), Kubernetes, and Azure for those purposes.
In benchmarks WSL 1's performance is often near native Linux Ubuntu, Debian, Intel Clear Linux or other Linux distributions. I/O is in some tests a bottleneck for WSL. The redesigned WSL 2 backend is claimed by Microsoft to offer twenty-fold increases in speed on certain operations compared to that of WSL 1. In June 2020, a benchmark with 173 tests with an AMD Threadripper 3970x shows good performance with WSL 2 (20H2) with 87% of the performance of native Ubuntu 20.04.0 LTS. This is an improvement over WSL 1, which has only 70% of the performance of native Ubuntu in this comparison. WSL 2 improves I/O performance, providing a near-native level.
A comparison of 69 tests with Intel i9 10900K in May 2020 shows nearly the same relative performance. In December 2020, a benchmark with 43 tests with an AMD Ryzen 5900X shows good performance with WSL 2 (20H2) with 93% of the performance of native 20.04.1 LTS. This is an improvement over WSL 1, which has only 73% in this comparison.
WSL 2
Version 2 introduces changes in the architecture. Microsoft has opted for virtualization through a highly optimized subset of Hyper-V features, in order to run the kernel and distributions (based upon the kernel), promising performance equivalent to WSL 1. For backward compatibility, developers don't need to change anything in their published distributions. WSL 2 settings can be tweaked by the WSL global configuration, contained in an INI file named .wslconfig in the User Profile folder.
The distribution installation resides inside an ext4-formatted filesystem inside a virtual disk, and the host file system is transparently accessible through the 9P protocol, similarly to other virtual machine technologies like QEMU. For the users, Microsoft promised up to 20 times the read/write performance of WSL 1. From Windows an IFS network redirector is provided for Linux guest file access using the UNC path prefix of \\wsl$.
WSL 2 requires Windows 11, or Windows 10 version 1903 or higher, with Build 18362 or higher, for x64 systems, and Version 2004 or higher, with Build 19041 or higher, for ARM64 systems.
WSL 2 and Windows 11 are in good shape with 95% performance of native Ubuntu 20.04 LTS.
Unlike WSL 1, WSL 2 does not support IPv6 connections.
See also
Azure Sphere
Windows Terminal
Xenix
References
Further reading
External links
WSL on Microsoft Learn
Compatibility layers
Virtualization software
Windows 10
Windows components