Install and Use Windows Subsystem for Linux(WSL)
Windows Subsystem for Linux is a utility developed by Microsoft to enable developers and Linux enthusiasts to run their favorite Linux environment natively on Windows 10 without the overhead of running a virtual machine. The way it works is similar to the way WINE works on Linux. WSL enables Linux binaries to run on Windows using a compatibility layer which translates the Linux system calls into Windows system calls.
Architecture
Arguably, WSL works better on Windows, than WINE does on Linux and the reason behind it is because Linux is peculiar in terms of its architecture. While most Operating systems consist of a Kernel and a whole suite of libraries and features built around that Kernel, Linux is just a Kernel. Most GNU/Linux distros take this Kernel and build an operating system stack on top of it. Depending on how you chose to build this stack you get different distributions like Debian, RedHat, etc.
To run Linux environment on Windows you would need to enable the WSL feature (we will cover this shortly) and then go to the Microsoft store to get a copy of your favourite distribution (Ubuntu, Debian, OpenSUSE, etc).
The first step enables the syscall translation layer and the second step brings in a light-weight stack of software to give you a complete Linux OS to run atop the WSL feature. Doing the opposite, that is to say running Windows applications on Linux is much harder because Windows is much more than just the NT kernel.
Because of this reason there’s no virtual machine involved in implementing WSL, making it an attractive option. You won’t have any loss in performance because no VMs are involved, just a native light-weight syscall translation layer.
Installation and Setup
On your Windows 10 PC, search for “Turn Windows features on or off” by clicking the Windows key and typing the same into the Start Menu. Once the Windows Features menu is opened scroll to the bottom where you will find “Windows Subsystem for Linux” feature. Check that box and click OK.
Windows would take care of the set up from here on and once everything is done it would require you to reboot your system to finalize the changes. After the reboot you can go to Microsoft Store and look for your favorite distribution in there.
You can search the store for your favorite distribution. Below is a screenshot of some of the most used distributions. You can see two variants of OpenSUSE, a Debian app and Kali Linux.
Of course, the most popular distribution is still Ubuntu with both 16.04 and 18.04 LTS available in the store.
Now you just have to pick the distribution that you want and install the corresponding app. We will be installing Ubuntu 18.04 LTS for our WSL environment. It is about 215 MB in size, much smaller than an entire Ubuntu installation.
Once, the app is installed you can launch it directly from the Microsoft Store app or by searching for it in your Start Menu. Upon being launched for the first time, it will take some time to set things up for you.
It might take upto 5 minutes, but once that is done you will be prompted to enter your new UNIX username and password and you are good to go!
The terminal launched will offer you almost all the functionalities of a Ubuntu system, except the GUI. Since most of the UNIX/Linux capabilities come for the power of the terminal this can get you a long way.
For example, we can start using this environment by updating all the packages installed in it.
Things you can and can’t do in WSL environment
Now, the question that arises in everyone’s mind is — What’s the catch?
Let’s consider the opposite case. With technologies like WINE we know that not everything that can be done in Windows can be done on Linux. Low level system libraries like DirectX will not be available on Linux and a lot of applications on Windows rely on such libraries.
Operating systems like Windows 10, FreeBSD or Illumos are full-fledged operating systems, not just the kernel. With Windows since most of the libraries are proprietary and that makes the matter more difficult. This makes the job of a project like WINE, much harder.
With trying to emulate Linux on Windows, the opposite is true. Linux’s tight set of ABI calls (or syscalls) is all you need to translate into Windows to run everything on top of it. If we try to ask the Ubuntu on WSL what Kernel it is running, it will give you a Linux kernel version number, with Microsoft mentioned alongside the version number to indicate that this is not the head branch of the Linux kernel project.
If we dig deeper, we will find that while high level functionalities like filesystem layout, and network configurations are shown, the lower level activities like block storage layout won’t work.
For example, the following commands would work as expected:
Both the commands tell you information about your native system which is actually running Windows. It is not anything like running a VM where there are different network interfaces and different filesystems entirely.
However, commands like lsblk won’t work, because lower level block storage isn’t what Linux expects it to be. Similarly, installing OpenZFS is futile because OpenZFS installs a few loadable kernel modules and we don’t have a Linux kernel just an illusion of it.
The same is true if you are trying to run docker. When installing Docker, Ubuntu won’t complain, however, Docker service would not start, as it depends on Systemd which is absent in this subsystem.
You can, however, run a plethora of services and bash utilities to make your life easier. If you manage Linux servers for a living, you don’t have to have Linux on your desktop as well. You can run SSH clients, Docker client, bash, utilities like grep and awk, as well as your favorite programming language from Python to Rust in this environment without polluting your Windows system.
You can also run your CD/CI automation using Ansible, Puppet or any other technology that you prefer. That is to say, anything a DevOp, a web or application developer or tester would require from a Linux system can be achieved with WSL except for the people working with system software and/or kernel development.
Conclusion
Got your own thoughts or experience with Windows Subsystem on Linux? Or maybe you still have questions that you need answers to. Contact us with your queries and we will cover that topic for you.