Tag: Windows Subsystem for Linux 2

Windows Subsystem for Linux 2 WSL2 on Windows Server

How to Install WSL 2 on Windows Server

A couple of months ago Microsoft announced the Windows Subsystem for Linux 2 (WSL 2), which is a successor of the Windows Subsystem for Linux shipped a couple of years ago. WSL 2 is currently available for Windows Insiders running Windows 10 Insider Preview Build 18917 or higher and with the Docker Tech Preview, you can now even run Docker Linux Container directly on WSL 2. With the latest Windows Server Insider Preview build 18945, you are also able to run WSL 2 on Windows Server. In this blog post, I am going to show you how you can install the Windows Subsystem for Linux 2 (WSL 2) on Windows Server. The Windows Subsystem for Linux was already available in earlier versions of Windows Server; however, WSL 2 brings a lot of new advantages.

The Windows Subsystem for Linux was in Windows 10 for a while now and allowed you to use different versions of Linux on your Windows 10 machine. With WSL 2, the architecture will change drastically and will bring increased file system performance and full system call compatibility. WSL 2 is now using virtualization technology (based on Hyper-V) and uses a lightweight utility VM on a real Linux kernel. You can find out more about WSL 2 in the release blog or on the Microsoft Docs Page for WSL 2.

Install Windows Subsystem for Linux 2 (WSL 2) on Windows Server

Here is how you can install WSL 2 on Windows Server.

Prerequisites:

After you have installed a new Windows Server with the Windows Server Preview build, you will need to add the following features:

  • Microsoft-Windows-Subsystem-Linux
  • VirtualMachinePlatform

To enable these features, run the following command:

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
 
Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform

These commands will need a restart to complete.

Windows Subsystem for Linux 2 WSL2 on Windows Server

Windows Subsystem for Linux 2 (WSL2) on Windows Server

Now you can install your Linux distribution which is available in WSL. You can also find the links to the Linux distro packages here: WSL distro packages. In my case, I am going to use Ubuntu 18.04, which is currently working with WSL 2.

Invoke-WebRequest -Uri https://aka.ms/wsl-ubuntu-1804 -OutFile ~/Ubuntu1804.zip -UseBasicParsing
md C:\Distros\Ubuntu1804
Expand-Archive ~/Ubuntu1804.zip C:\Distros\Ubuntu1894

Before you start and configure your WSL distro, I recommend that you set the WSL default version to 2. This will make the setup of your distro much faster.

wsl --set-default-version 2

Now you can start ubuntu.exe to run WSL.

C:\Distros\Ubuntu1894\ubuntu1804.exe

I hope this gives you a step-by-step guide on how you can install WSL 2 on Windows Server. Remember this is currently in preview, and not for production use. If you want to install the Windows Subsystem for Linux on Windows Server 2019, check out this blog post: Install Windows Subsystem for Linux on Windows Server.



Docker Desktop WSL 2 Tech Preview

Run Linux Containers with Docker Desktop and WSL 2

Today, Docker launched the first Tech Preview of the Docker Desktop WSL 2. This means you can now use Docker Desktop and the Windows Subsystem for Linux 2 (WSL2) which is using the hypervisor in the background to run Linux containers on Windows 10. With the significant changes to the Windows Subsystem for Linux 2, you can now take advantage of these improvements with your Docker Desktop client.

Docker Desktop WSL 2 is currently in Tech Preview, and it also requires the Windows 10 Insider Preview builds. That means you should only use for not production environments.

WSL 2 introduces a significant architectural change as it is a full Linux kernel built by Microsoft, allowing Linux containers to run natively without emulation. With Docker Desktop WSL 2 Tech Preview, users can access Linux workspaces without having to maintain both Linux and Windows build scripts.

Docker Desktop also leverages the dynamic memory allocation feature in WSL 2 to greatly improve the resource consumption. This means, Docker Desktop only uses the required amount of CPU and memory resources, enabling CPU and memory-intensive tasks such as building a container to run much faster.

You can find more information about the Tech Preview here.

Prerequisites

To run the Docker Desktop WSL 2 Tech Preview, you will need to set up the Windows Subsystem for Linux 2 (WSL 2) first. You can do that using the following guide, or follow these steps:

Install Windows 10 Insider Preview build 18932 or later.

Install the Windows WSL feature and the Windows Virtual Machine Platform feature running the following commands:

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
 
Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform

Download WSL Linux distribution based on Ubuntu 18.04 from the Microsoft Store. You can read more about Linux on Windows 10 here. The distribution needs to be set as the default WSL distro.

Enable Virtual Machine Platform

Enable Virtual Machine Platform

Make sure that the WSL distro is running in WSL 2 mode. You can check the list of distros installed on your Windows 10 machine, with the following PowerShell command:

wsl -l -v

To set the distro to WSL 2, you can run the following command. Change the name of the distro:

wsl --set-version DistroName 2
Install WSL 2

Install WSL 2

To find out more about installing WSL 2, check out the Microsoft Docs page.

How to set up Docker and WSL 2

First, you will need to download the Docker Desktop WSL 2 Tech Preview here. Make sure you already configured all the WSL 2 steps described in the prerequisites, before you install the Docker WSL 2 Tech preview. If you are prompted if you want to use Linux containers or Windows containers during the installation, select Windows containers. If you choose Linux containers, you will have the classic Docker experience with a Hyper-V VM.

Docker Desktop WSL 2 Tech Preview Menu

Docker Desktop WSL 2 Tech Preview Menu

Run the installation wizard, and after a successful installation, the Docker Desktop menu displays the WSL 2 Tech Preview option. You can select WSL 2 Tech Preview from that menu to start and configure the daemon running WSL 2.

Docker Desktop WSL 2 Tech Preview

Docker Desktop WSL 2 Tech Preview

You can switch between the classic daemon or the Windows Subsystem for Linux 2 with the following commands:

# Switch to classic deamon
 
docker context use default
 
# Switch to WSL 2
 
docker context use wsl
Linux Container on Windows 10

Linux Containers on Windows 10

You can now also do crazy things like run SQL Server on Linux in a Docker container on Windows 10.

SQL Server on Linux Docker Container Windows 10 WSL 2

SQL Server on Linux Docker Container Windows 10 WSL 2

I hope this gives you a good overview of how you will be able to run Linux containers on Windows in the future. Again this is still a Tech Preview, and we might see many changes to that feature. If you want to know more, read the full blog post on the Docker page. Also, check out the current Linux Container on Windows documentation. If you any questions, feel free to leave a comment.



Install WSL 2

Install WSL 2 on Windows 10

With the Windows 10 Insider Preview Build 18917, the team also ships the first version of the Windows Subsystem for Linux 2 (WSL 2), which was announced at the Microsoft Build 2019 conference. In this post, I am going to show you how you can install WSL 2 on your Windows 10 machine.

The Windows Subsystem for Linux (WSL 1) was in Windows 10 for a while now and allowed you to use different Linux distros directly from your Windows 10 machine. With WSL 2, the architecture will change drastically and will bring increased file system performance and full system call compatibility. WSL 2 is now using virtualization technology (based on Hyper-V) and uses a lightweight utility VM on a real Linux kernel. You can find out more about WSL 2 in the release blog or on the Microsoft Docs Page for WSL 2.

WSL 2 Architecture

Requirements

To install WSL 2, you will need the following requirements:

Install WSL 2

To install the Windows Subsystem for Linux 2 (WSL 2), you need to follow these tasks.

  • Enable the Windows Subsystem for Linux Optional feature (WSL 1 and WSL 2)
  • Install a distro for the Windows Subsystem for Linux
  • Enable the ‘Virtual Machine Platform’ optional feature (WSL 2)
  • Configure the distro to use WSL 2

Enable the Windows Subsystem for Linux

To run the WSL on Windows 10 you will need to install the optional feature:

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

Install a Linux distro for the Windows Subsystem for Linux

If you don’t already have installed a WSL distro, you can download and install it from the Windows 10 store. You can find more here: Crazy times – You can now run Linux on Windows 10 from the Windows Store

Enable the Virtual Machine Platform feature

WSL 2 Enable Virtual Machine Platform

WSL 2 Enable Virtual Machine Platform

To make use of the virtualization feature for WSL 2, you will need to enable the optional Windows feature. You can run the following PowerShell command to do this. You will need to start PowerShell as an Administrator. After you run this command, you might need a restart of your computer.

Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform

Set WSL distro to use version 2

After you completed the first two steps, you will need to configure the distro to use WSL 2. Run the following command to list the available distros in PowerShell:

wsl -l -v

To set a distro to WSL 2 you can run the following command:

wsl --set-version DistroName 2

You can also set WSL 2 as the default:

wsl --set-default-version 2

To find out more about installing WSL 2, check out the Microsoft Docs page.

If you are now running your distro using WSL 2, you can now see that there is a Virtual Machine worker process running and if you search a little bit more, you can also find the VHDX file of the distro.

WSL 2 VHDX file

I hope this helps you and gives you a quick overview, if you have any questions, let me know in the comments and check out the WSL 2 FAQ. The Windows Subsystem for Linux 2 Kernel is also open-source, you can follow the project on GitHub.

By the way, you can now also start using Docker Desktop together with the Windows Subsystem for Linux 2.