What is Windows Subsystem for Linux (WSL and WSL2)? — Linux in Windows
Windows Subsystem for Linux has gained a lot of popularity over the last few Windows 10 updates. Among the barrage of features and additions, WSL stands out as a welcome change. While most of us depended on Virtual Machines to get the job done, WSL seems to be a remarkably lighter alternative to handle the necessary tasks. The latest addition is the improved WSL2.
So what is WSL? Let’s have a look at what WSL is. Also, check out the differences between WSL and WSL2. Plus, we’ll compare each of them with Virtual Machines, so that we can have a better understanding of the use case scenarios.
What is WSL (Windows Subsystem for Linux)?
WSL was the initial release added to the Windows 10 version 1607 update. WSL is an optional feature in Windows 10 that provides the users with a Lightweight Linux console environment within the Windows Operating System. Windows Subsystem for Linux adds a compatibility layer, which allows you to run the Linux binaries to the native Windows 10 OS—thus eliminating the need for the installation of Virtual Machine to run most command-line tasks.
How does WSL work?
Well, WSL translates the Linux system calls returned by the process to the Windows kernel calls while a Linux Distro sits on top. It is thus eliminating the need for the Linux kernel in the process. So basically, it is Linux inside Windows. Furthermore, there is no emulation involved whatsoever.
This feature follows suit with Microsoft’s ambitions to bring the Linux experience to Windows 10 natively. One of the reasons why Linux operating systems are highly popular is due to its superior dev environment. With the implementation of the Windows subsystem for Linux, Redmond giant plans to bring the best of both worlds to the Developers.
Why use WSL?
- Linux Command line tools
- Windows 10 Filesystem access
- No VM needed
The Windows Subsystem for Linux allowed the developers and system administrators to use core command-line tools and services. But most importantly, the bash shell. The availability of package tools such as apt and dpkg in of itself affords developers a plethora of command-line GNU applications.
Additionally, Windows 10 filesystem and drives can be accessed and handled within the WSL console interface itself. The drive partitions are mounted at launch within the path of /mnt/. For example, the logical drive C:\ mount at /mnt/c.
Talking about the interface in the WSL, we are limited to the command-line interface. GUI (Graphical User Interface) does not exist. Although we can run a minimal number of GUI applications with the help of small tweaks, the terminal console is all we would be working with.
Moreover, the list of available distributions is sufficient. Although Ubuntu was the only one distro, which was available initially, the list keeps growing continuously. Also, we can install more distros unavailable in the list with the use of some workarounds.
Why not Use WSL?
First of all, there’s the obvious problem of scalability. As there is no native Linux kernel support, comprehensive processes and tasks are limited.
Services like Docker are not supported in the first generation release of the Windows Subsystem for Linux owing to the unavailability of kernel-level support for Linux containers.
Network communication (although possible) requires several layers to pass through, making the WSL not ideal for low-level networking processes.
For tasks requiring more peripheral access like graphics, sound, and high-speed file I/O, WSL may not be the best option.
WSL2: How is the architecture different from WSL1?
The new and improved WSL2 is the apparent successor to WSL, which is available from the Windows 10 version 2004. WSL2 architecture is entirely different from WSL1. Unlike WSL1, which runs as a translation layer, the Windows subsystem for Linux 2 has a virtual machine with an actual Linux Kernel that can immediately react to system calls. Such an architecture enables Full System call capabilities.
Additionally, the Linux Kernel used in the WSL 2 architecture, is a Microsoft developed open-source Linux Kernal. Along with a significant overhaul from its predecessor, WSL2 has under the hood changes that help alleviate some of the drawbacks of the original version. Let’s review these improvements a bit more —
WSL2 vs. WSL1: How is WSL2 better?
- An Actual Linux Kernel
- Full System Call Capability
- Socket/Networking Performance
- File System Performance
As we said before, the whole architecture changed dramatically with the new Windows Subsystem for Linux 2 release. WSL2 is a genuinely lightweight virtual machine based on Microsoft’s hardware virtualization service Hyper-V. Having a native hypervisor helps the WSL2 implementation to pull clear of any disadvantages that WSL1 had when it first launched.
For example, the availability of a real Linux Kernal enables the user to execute tasks with full system call compatibility. So, the platform becomes much more potent for handling Linux-based applications. Also, services like Docker and fuse will be compatible.
File I/O performance is much improved. Therefore, operations such as apt-installs, npm installs will be snappier. Furthermore, this should be the case for all read and write and services as well.
(Note: Microsoft did mention slower cross OS file speeds in the initial builds.)
Finally, Version Switching is as simple of a process there is. Along with this, the networking and socket performances has had considerable improvements.
WSL/WSL2 vs. VirtualBox/ Virtual Machines?
So how does it stand out from the traditional Virtual Machines? After all, VM, such as Virtual BOX, remains to be the most popular option that users have for a similar cross-platform experience.
A Virtual Machine creates an environment inside your system that acts as a separate virtual system with all the hardware components like CPU, RAM, Storage with the help of Hyper Visors. Such an architecture enables the user to have a proper and complete system within the operating system that you are running. Unlike WSL/WSL2, Virtual Machines can run full graphical interfaces as the environment itself is a full-fledged Linux workspace. But as usual, there are caveats.
A Virtual Machine is Isolated. What this means is that you won’t be able to access files outside the Virtual System (a.k.a. your actual system files).
Slower boot and performance: Virtual machines typically run inside an operating system. So, they can access the actual hardware only through the OS, which, in turn, results in performance issues. To put it simply, Virtual Machines are only as powerful as your hardware allows it to be. That said, most modern hardware is powerful enough for such heavy-duty tasks.
Memory Usage: Whenever we require the need for a VM, a large chunk of memory must be dedicated to it at all times.
Management: Virtual Machines have operating systems that require management.
Which Should You Use?
Now that we have learned how each of these services works, let’s look at the use case scenarios:
Why Choose a Virtual Machine?
- You require all the power and features of Linux.
- For the Larger scale, Production level works.
- GUI (Graphical User interface)
- Graphical or Network-intensive workloads.
When to choose WSL/WSL2?
- For using basic Linux commands.
- You have less powerful hardware.
- You need memory/storage efficiency.
- When you need faster I/O.
- Don’t want to deal with the hassle of installation/management/overheads of a VM.
Finally, it is safe to say that developers are the clear winners as they are the biggest beneficiaries of these new features that Windows 10 brings.