Crypto Lab: Windows Subsystem for Linux (WSL)

Overview

The focus of the Crypto Lab series is to provide some useful information on some tools and controls used in systems security engineering, with a cookbook approach.

This page will focus on the installation, care and feeding of the Windows Subsystem for Linux (WSL), by far the most interesting feature that Microsoft has introduced to Windows – ever.

Essentially (to paraphrase and slightly mangle) WSL is a very substantial command line version of Ubuntu Linux, that runs directly on top of the Windows kernel. This has technically been possible since NT4.0, which had a POSIX kernel, and was derived from Dave Cutler’s work at DEC on VMS. Essentially the NT4.0 kernel was the first fully abstracted kernel with preemptive multitasking – just like the mainframes. This architecture allowed for any operating system to be built on top of this kernel as a subsystem, but unfortunately from 1993 to 2016, the only available options were the Windows subsystem. This architecture also allowed Windows to be ported to other CPU architectures like the MIPS, DEC Alpha and the PowerPC  by rewriting parts of the kernel and parts of the HAL (Hardware Abstraction Layer), while leaving nearly all of the OS itself unmodified.

Fast forward to 2017, Windows runs on IA32/64 platforms (without any alternative CPU options), and Microsoft in partnership with Canonical have developed a native Linux subsystem that runs in parallel with the Windows operating system.

It is limited to the command line, although there are some hacks to enable an approximation of a Linux Desktop (ie VNC). In the following sections we will outline how to enable, install and maintain WSL on your Windows 10 installation.

Setting up Windows Subsystem for Linux (WSL)

Installation

  1. Verifying your version of Windows 10: In the search box, enter ‘about’ and select the ‘About your PC’ option. The window should be similar to this and it must indicate build 14393 or greater and 64 bit operating system.
  2. Enabling Developer Mode: In the search box, enter ‘developer’ and select the ‘For Developer Settings’ option. The window should be similar to this. Enable Developer mode.
  3. Installing WSL: In the search box, enter ‘features’ and select the ‘Turn Windows features on or off’ option. The window should be similar to this. Check the ‘Windows Subsystem for Linux (beta)’ option, and click ‘OK’. 
  4. Powershell Enabling: In the search box, enter ‘powershell’ and right click over the ‘Powershell’ option, and select ‘run as Adminstrator’, and confirm. In the Powershell window enter:
    Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

    Follow the prompts and reboot if it calls for it.

  5. Bash Installation: In the search box, enter ‘cmd’ and select the ‘Command Prompt’ option. Type ‘bash’ and enter. Follow the prompts. Create a username and password when prompted. This user/password has nothing to do with any of the Windows accounts and is specific to the WSL instance.
  6. Bash Operation: In the search box, enter ‘bash’ and select the ‘BASH on Ubuntu on Windows’ option. 
  7. Updating Bash: In the Bash window, enter:
    sudo apt-get update
    sudo apt-get upgrade

Fun and Games with WSL

  1. WSL About: From inside the Bash window, enter:
     sudo lsb_release -a

  2. WSL Driving Mappings: From inside of the Bash window, enter:
     ll /mnt/c

  3. Explorer OpenWSL: Download the open-wsl terminal (https://github.com/goreliu/wsl-terminal). In the tools directory run the JS-App “add-open-wsl-here-menu.js”. This will allow you to right click in any directory and open a WSL terminal to that directory.

Care and Feeding of WSL

  1. About LXRun: From a Windows command prompt, enter:
     lxrun

  2. Uninstalling WSL Instance: From a Windows command prompt, enter:
     lxrun /uninstall /full
  3. Resetting WSL Environment: From a Windows command prompt, enter:
    C:\> lxrun.exe /uninstall /full
    C:\> lxrun.exe /install
  4. Updating WSL: This appears to be exactly the same as apt-get update/upgrade. From a Windows command prompt, enter:
     lxrun.exe /update

Wrapup

Note that this does not represent the authoritative source for any of this material. For that please refer to the links below. This is just intended to be a more concise aggregation of the more interesting items provided in the links below.

References