WSL – What is it? Linux on Windows – how cool is that!

WSL Windows Subsystem for Linux is a compatibility layer for running Linux binary executables (in ELF format) natively on Windows 10 and Windows Server 2019.

Translation: WSL allows you to run Linux on your Windows platform without installing virtualization software from VM Ware, Oracle (my favorite), Microsoft or elsewhere.

In May 2019, WSL 2 was announced, introducing important changes such as a real Linux kernel, through a subset of Hyper-V features. WSL 2 is a major upgrade over the original version of WSL that Microsoft introduced back in 2017. WSL 2 isn’t a mere version bump. It’s faster and more versatile. Future Linux kernel updates will even be released as Windows 10 software updates.

Microsoft also plans to let users run desktop Linux apps on Windows 10 and leverage GPU-intensive tasks. It’s also making it possible to install WSL in a single command. For now, unless you’re riding the latest insider builds, WSL 2 is something that requires a bit of effort to set up — but isn’t having a full Linux system at your beck and call inside of Windows worth that? (source)

So, let’s get started:

The basics: https://www.omgubuntu.co.uk/how-to-install-wsl2-on-windows-10

Install WSL 2 on Windows 10

Requirements

To install WSL 2 on Windows 10 you need the following things:

  • Windows 10 May 2020 (2004), Windows 10 May 2019 (1903), or Windows 10 November 2019 (1909)
  • A computer with Hyper-V Virtualization support (this is done in BIOS)

The Windows 10 May 2020 update was released in May 2020 but not every device is able to upgrade right away. To see if the Windows 10 May 2020 Update is available on your computer go to Settings > Update & Security > Windows Update.

In August Microsoft backported WSL 2 to older versions of Windows 10. Anyone on the 1903 or 1909 builds can install WSL 2 too – but must first install Windows Update KB4566116.

Advanced (and impatient) Windows users can force install the Windows 10 May 2020 update, just keep in mind that you may encounter missing drivers, GUI glitches, or other hardware hiccups if you go this route.

Technically you can install WSL 2 on an “insider” build of Windows 10 build 18917 or later. I’m not too familiar with how the “insider” build system works so just be aware that the rest of this post is based on using the feature on a stable version of Windows.

Your computer also needs to support Hyper-V Virtualization to run WSL 2. You can check your Hyper-V support to be sure.

If you don’t meet both of the requirements then you cannot install or enable WSL 2 — but you can use WSL 1.

The process of installing WSL 2 on Windows 10 is this:

  1. Enable WSL 2
  2. Enable ‘Virtual Machine Platform’ 
  3. Set WSL 2 as default
  4. Install a Linux distro

I’ll walk through each of these steps in turn using the PowerShell app, which you need to run as an administrator. You can find PowerShell in the Windows Start Menu.

Note: it is possible to install WSL 1 using a GUI too but it’s much faster to use the command line, and since WSL is a CLI tool it kinda makes sense too!

Step 1. Enable WSL

Regardless of which version of WSL you want to use you first need to enable it. To do this open the PowerShell tool as an Administrator and run the command below. Be careful not to mistype or leave out any character in the command:

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

Only want to use WSL 1? You can skip to step 4.

Step 2. Enable ‘Virtual Machine Platform’ 

WSL 2 requires Windows 10’s “Virtual Machine Platform” feature to be enabled. This is separate from Hyper-V and hands some of the more interesting platform integrations available in the new version of the Windows Subsystem for Linux.

To enable Virtual Machine Platform on Windows 10 (2004) open PowerShell as Administrator and run:

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

To enable Virtual Machine Platform on Windows 10 (1903, 1909) open PowerShell as Administrator and run:

Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -NoRestart

To ensure all of the relevant bits and pieces fall neatly in to place you should restart your system at this point or you may find that things don’t work as intended.

Note: At this point I got the message: “WSL 2 requires an update to its kernel component. For information please visit https://aka.ms/wsl2kernel.” so needed to install the MSI Linux kernel update package available here: https://docs.microsoft.com/en-us/windows/wsl/install-win10#step-4—download-the-linux-kernel-update-package

Step 3. Set WSL 2 as default

Open PowerShell as Administrator and run this command to set WSL 2 as the default version of WSL:

wsl --set-default-version 2

You can (at any time) configure a distro to run in WSL 1 mode if you need to.

Step 4. Install a distro

With WSL and the necessary virtualisation tech all in place all that is left for you to do is pick and install a Linux distro from the Microsoft Store.

Several different distros are available, including OpenSUSEPengwinFedora Remix, and Alpine Linux. But my personal recommendation is (naturally) Ubuntu 20.04 LTS (though 18.04 LTS and 16.04 LTS are also available).

To install Ubuntu on Windows 10 open the Microsoft Store app, search for “Ubuntu 20.04”, and hit the “Get” button:

Ubuntu 20.04 LTS on the Microsoft Store

Whilst you in the Microsoft Store I highly recommend that you also install the open source Windows Terminal app. This tool is designed to give you the best possible WSL experience:

Windows Terminal on the Microsoft Store

5. Use WSL 2

When you installed Ubuntu (or a different Linux distro) a shortcut was added to the Start Menu. Use this to “open” Ubuntu (or whichever distro you chose). The first time you run the distro things will seem a little slow. This is expected; the distro has to unpack and decompress all of its contents — just don’t interrupt the process.

You will also be promoted to set a username and password for use on the distro. Try to pick something you won’t forget.

Convert Ubuntu on WSL 1 to WSL 2

If you use WSL 1 you can upgrade an existing WSL 1 installation to WSL 2. To convert an existing WSL 1 distro to WSL 2 run the following in PowerShell, e..g,:

wsl.exe --set-version Ubuntu 2

You should replace ‘Ubuntu’ with the name of whichever distro your WSL 1 install runs.

Other useful links:

Microsoft Put a Real Linux Kernel Inside Windows 10

Windows Subsystem for Linux Documentation

Frequently Asked Questions about Windows Subsystem for Linux

Windows Subsystem for Linux (WSL): what can’t I do with the Ubuntu application for Microsoft Windows?

And this:

Kali Linux on Windows in 5min (WSL 2 GUI)

And when that doesn’t work as planned and you get an error, first try installing ‘xming‘ in Windows, and if there’s still no joy, then you need to install ‘dbus-x11’ via the Kali Linux terminal interface (sudo apt-get install dbus-x11).

Hacking with WSL2

And this:

WSL2 Ubuntu GUI

https://medium.com/@gulfsteve/hacking-with-wsl2-ede3e649e08d

Enjoy!

PS – When using WSL to load a Linux GUI (Graphical User Interface), there are a few steps to go through. For practice, I loaded both the Kali and Ubuntu GUIs on my test Windows 10 machine. Starting with Kali, here are the steps to get into the Kali GUI after restarting the PC:

  1. Start the Kali Linux terminal
  2. Type ‘ip add’ to get the eth0 inet address (ex. 172.22.194.99) – note this address, you’ll need it later
  3. Type ‘sudo service xrdp start’, then enter the password you set for Kali – a message will let you know that the Remote Desktop Protocol Server has started
  4. Start the Microsoft ‘Remote Desktop Connection’ service
  5. In the dialog box that appears, enter the inet ip address from Step 2 (this address will likely change from one restart to another), then click ‘Connect’
  6. In response to the Warning message that appears (this is normal), select ‘Yes’ to continue
  7. In this next ‘XRDP’ dialog box keep ‘Xorg’ under ‘Session’, then enter the user name and password for your Kali instance

That’s it. Eventually I’ll find a way to script this so there’s just one step to connect, but this is the way sausage is currently made.

OK, so let’s rinse and repeat for Ubuntu. I have exited my Kali session and will restart the computer before proceeding. Here are the steps for starting the Ubuntu GUI (which I have been able to automate a bit more than the Kali start procedure:

  1. Start the Ubuntu Linux terminal
  2. Type ‘sudo /etc/init.d/xrdp start’, then enter your password for your Ubuntu installation
  3. The response should read ‘Starting Remote Desktop Protocol Server’
  4. Start the Microsoft ‘Remote Desktop Connection’ service
  5. For this installation we’ll use ‘localhost:3390’ (no IP address required), then click ‘Connect’
  6. In response to the Warning message that appears (this is normal), select ‘Yes’ to continue
  7. In this next ‘XRDP’ dialog box keep ‘Xorg’ under ‘Session’, then enter the user name and password for your Ubuntu instance

What could be easier than that? Well, I can think of a lot of things. But you have to admit that this was a fun adventure – right? If so, you are truly a geek. Congrats!

About Glen

Profile information
This entry was posted in Uncategorized. Bookmark the permalink.