Our Blog

where we write about the things we love



Windows Subsystem for Linux

One of the more interesting announcements at the recent Microsoft Build technology conference was the introduction of the Windows Subsystem for Linux, variously referred to as “Bash on Windows” or “Bash on Ubuntu on Windows”. In this blog post, we’ll take a brief at what the Windows Subsystem for Linux (WSL) is, what it isn’t, and why it is a useful tool for Windows developers.

Windows Subsystem for Linux

Can’t you run Linux software on Windows already?

Sort of.

There already exist a number of toolkits for running Linux “userspace” programs on windows – Cygwin, MSYS2 and MinGW, etc. The goal is to provide Windows users with access to the “userspace” tools used extensively on Linux distributions (e.g. sh, sed, awk, grep), popular text editors (e.g. emacs, vim) and compilers (e.g. gcc).

All of these toolsets have differing goals and implementations, but at their core they all work by carefully re-implementing key APIs to work on Windows, and cross-compiling the userspace programs from source into native Win32 executables.

Windows  Susbystem for Linux: Bash and CMD equivalents
Figure 1 - The same “MinGW32” executables invoked under both MinGW32 Bash and CMD.exe

So how is WSL different?

WSL aims to tackle this problem in a more direct way – by directly implementing Linux kernel system calls using Windows kernel functions.

The goal is to provide a complete native Linux userspace running under windows, that is: A Linux filesystem and userspace tools (ls, grep, awk, sed, etc), running natively on a windows kernel.

The filesystem and userspace is provided by the popular Ubuntu distribution of Linux – when you install Windows Subsystem for Linux, you are actually installing a cut-down version of Ubuntu without the Linux kernel.

When you run grep from the Bash prompt provided with WSL, you are not running a Win32 executable, but rather a native Linux ELF executable compiled to run on Ubuntu.

How does it work?

WLS provides you with a Linux filesystem, stored inside the Windows filesystem (specifically, you can find it in your AppData directory).

When you launch Bash, you are placed inside this separate filesystem. Each user has their own Linux filesystem, and at this stage you are authenticated as the root user (this will change in the future). Any changes you make within this filesystem are limited to your account and you can reset the filesystem at any time.

You can access your Windows drives via the /mnt directory.

Windows  Susbystem for Linux: LS c:
Figure 2 - Listing the contents of my C: drive

Many standard Ubuntu command-line programs will work as expected. For example: The Ubuntu package manager apt can be used to install software directly from the Ubuntu package repositories.

Keep in mind that this is beta software, and not everything will be working.

So why the effort?

Couldn’t I just run Linux in a VM?

While you could provision and run a virtual machine to host a Linux distro this requires you to allocate system resources directly. The advantage LSW provides is native execution which requires you to allocate only the resources required by the program you are executing. No need to start a virtual machine and give it two gigabytes of RAM so that you can run Ruby!

This is a big win for developers who are already comfortable with the GNU/Linux tool ecosystem. With both the filesystem and the tools available these users can feel at home even on a Windows box.

Another benefit is access to the huge amount of software which either only runs under Linux or has had problems porting to Windows. For example, many Ruby programs assume they will be running on some variant of Linux, and behave strangely (or do not work at all) when running on Windows.

Can I run my web server under the WSL?

Yes, but you shouldn’t.

The WSL is intended as a developer/engineer’s tool. While you could install and use Ruby, Apache, Redis and MySQL, there are no guarantees that software will perform at scale under the WSL. Instead, you should use the WSL to develop your application; and then deploy to production on a box running Linux proper.

Wrap up

And in that last paragraph I think we’ve found a reason for this feature. The Microsoft of ten years ago wouldn’t have dreamed of providing a feature like the Windows Subsystem for Linux.

The reality is that many software developers live a dual life – perhaps writing client applications that run on Windows desktops and server-side applications that run on Linux servers. With the WSL developers can truly write software targeting both Windows and Linux at the same time, on the same box, using a single operating system.

The Microsoft of today hopes that you will then choose to run those Linux servers in the Azure cloud.

Posted by: Benjamin Fox, Modern Applications Developer | 21 April 2016

Tags: Build, Bash, Linux

Top Rated Posts

Blog archive

Stay up to date with all insights from the Intergen blog