Skip to main content

Windows Subsystem for Linux Internals

Background

Windows Subsystem for Linux was developed by Microsoft to enable command line programs compiled for the Linux operating system to be executed on Windows.

To explain the architecture I would like to show the evolution of OS design and how that has enabled this subsystem to be built.

Dark Ages (or Back in the Day)

Microsoft's MS-DOS was quite primitive in its design (compared to today's OS's). It is a single user OS that can execute one process at a time. DOS had an application programming interface to allow user programs to access some hardware in a device independent way, but only for character-based applications.

This allowed applications to display graphical elements emulated with text characters as these screenshots of Microsoft word for DOS show:


This is Microsoft Word version 1.


To use these programs you had to remember key combinations to bring up the menus and used the cursor keys to navigate around the screen.

If the application required fancy graphics, sounds or networking (or just wanted to allow the use of a mouse), then the application had to talk directly to that hardware using device-specific drivers.



If you changed your sound/network/video card, applications might stop working as they might not have drivers for it.

Windows

On 20th November 1985 Microsoft launched Windows version 1.0.

The first version of Windows ran on top of MS-DOS and presented a Graphical User Interface.


Windows 1 introduced the hardware abstraction layer into the PC application architecture. Windows 1 included drivers for video cards, a mouse, keyboards, printers and serial communications, and applications were supposed to only invoke The Windows APIs and not talk to the drivers directly.

The windows OS has evolved a great deal over the years and the original windows 1 architecture was still in use as the foundation of Windows ME release in 2000.

Starting in 1993 Microsoft created a purely 32 bit OS with no legacy code from Windows 1 architecture. The kernel created for Windows NT is still used as the base for current versions of Windows (although it has evolved since 1993).

This is the basic structure of windows today. User applications talk to a layer in the kernel that abstracts out all details of the hardware and presents a unified API to user applications.


## Linux

In 1991, Linus Torvalds, a student at Helsinki university wanted an OS where he could play with its source code and learn about its internals. He started using an OS called Minix written by professor Andrew Tanenbaum and documented in a book which was aimed at students learning operating systems design. While the source code for the Minix system was available, modification and redistribution were restricted.

This led Linus Torvalds to start writing his own OS which he called Linux.

The first message about Linux was actually posted to the comp.os.minix newsgroup on 25 Aug 1991 - First msg about Linux

Linux has a similar architecture to current Windows versions. no user application accesses hardware devices directly not even by talking to device drivers. User applications talk to a layer in the kernel that abstracts out all details of the hardware and presents a unified API to user applications.


Windows Subsystem for Linux

So, finally on to the subject of this post.

Microsoft hasn't always been a fan of Linux. Some people have even accused Microsoft of underhand tactics in the past designed to stop Linux being installed on PC's that also had Windows installed.

But eventually, they have realised that developers seem to like the open source OS and have started supporting it.

Windows Subsystem for Linux-August 2, 2016 (Windows 10 Build 1607

the Windows subsystem for Linux was written to allow text mode Linux programs to be executed on windows.

"WSL executes unmodified Linux ELF64 binaries by virtualizing a Linux kernel interface on top of the Windows NT kernel"

Basically, it performs real-time translation of Linux syscalls into Windows OS syscalls.




So what it boils down to is that Microsoft wrote a Linux kernel 'emulator', which allows programs that call into the Linux kernel user-space API to execute on windows and not know it. But being only the Linux kernel, there are no graphics calls. Sorry but Xeyes won't run. Unix has a unique take on windowing systems. but that is a large subject and probably best left for another post. This one is long enough for now.

References



Comments

Popular posts from this blog

Triathlon Training in the new year

So, my 2019 training has got off to a good start. I'm running regularly and my knees seem to be holding up. I've got a training plan to get me to a middle distance triathlon in September and I am managing the run distances I have set myself. I need to find some longer cycling routes to work and ones with a few hills too, but that shouldn't be a problem. my weekly cycling distance is okay, I just need to move to get my ebike to be doing less of the work. last week I did use my normal commuter bicycle and managed the whole four days as well as my runs, so that was a really good sign. Swimming won't be an issue, I have always found that to be the easy part of a triathlon (not that I'm fast, but I can keep going, and I did manage to swim the distance within the cut off time when I tried the ironman 70.3 last time) The main worry about going longer is my knees. I've got a 10K booked in late January which will test my knees out and I'm hoping that they hold ...

First race of 2019

As I am aiming for a middle distance triathlon in September, I want to make sure that I can complete it before shelling out the (rather high) entry fee. my main concern is that my knees cope with the run section which will be 21 Km (a half marathon). In the past, I have had a bit of trouble with my knees playing up. I thought it was because I had run too much (increased my training too quickly, too many races close together, that sort of thing). So for the last 8 months, I have been trying to acclimatise my knees by running around 5km three times a week To take stock of how my knees are with running, I decided to enter a 10K race. The race I entered was the Bristol Race For Chocolate 10K. It sounded like a fun race and was on 27th January, which would give me plenty of time to train for my main race in September. I wanted a 10K as it is just under half the distance of my target middle distance and if my knees cope with that then I have plenty of time to increase the distance...

Wales 500 Post 2

Day -1 (of the rally) So, tomorrow, Patrick and I will be riding up to set up our campsite ready for two days of (not quite off) roading. I've got my camping gear packed, but I've been getting confused about how to pack things that I will want whilst riding vs stuff to leave at camp. Then I realised that I've never done that before. whenever we've gone on a trip we've always stayed a night and then moved on to the next place. Only once have we set up and stayed in the same place for more than one night, and that was at Assen to watch the MotoGP. Guess I'll get it sorted today. I think I've got everything I need, except a way to pump up my tyres if I have a puncture. I have a puncture repair kit, but no pump. hmmm, will have to think on that. I think I will be taking a rucksack so that I can carry stuff out on the rides with me, but I may try to attach it to the back of the bike instead of wearing it as it might get too hot. Today is wet and rainy...