Chapter 18

Windows Subsystem for Linux

Linux on Windows Server

Installing WSL

WSL 2.0

Windows Subsystem for Linux (WSL) allows you to run a variety of Linux distributions on Windows computers. Windows Subsystem for Linux has been available for Windows 10 for several years, and distributions are available from the Microsoft Store. You can even use X-Windows server on Windows 10 to run Linux GUI applications.

Though you can’t use the Microsoft Store on Windows Server 2019, WSL is available and relatively easy to install. In this chapter, you’ll learn how to set up Windows Subsystem for Linux on Windows Server and how to install, configure, and manage Linux distributions.

Linux on Windows Server

Linux has been available on Windows Server through a variety of methods over the years, including Windows Services for UNIX that were available with Windows NT and Windows 2000 and third-party products, such as Cygwin; also, you can run Linux or BSD virtual machine on Hyper-V.

When it comes to running Linux utilities or hosting Linux workloads, Windows Server provides multiple options.

  • If you need access to Linux command-line utilities on a Windows Server computer, WSL provides you access to almost all utilities available in the most popular Linux distributions. You install and manage them in the same way you’d install or manage them from the command line on a Linux host.

  • If you need to host Linux container workloads, you can use Linux Containers On Windows (LCOW). You learned about LCOW in Chapter 10, “Containers.” In small- to medium-sized environments, it may be simpler to host Linux container workloads on a Windows Server instance than to manage both Windows and Linux servers separately. At present, you can’t host Windows container workloads on Linux computers.

  • If you need to host more complicated Linux workloads, many of the most popular Linux distributions are fully supported on Hyper-V. Also, you can integrate a Hyper-V IaaS deployment with an Azure IaaS deployment, shifting virtual machines running Linux to and from the cloud as required.

Although it is possible to run workloads such as the NGINX web server through WSL on a Windows Server host, you’d be far better off running such a workload using a container or virtual machine. WSL works best as a way of accessing additional command-line tools. If you want to host Linux-based workloads on Windows Server, Linux virtual machines and containers are far more robust solutions.

Installing WSL

The first step involved in installing WSL on Windows Server 2019 is to enable the Windows Subsystem for Linux optional feature. You can do this by running the following command and then restarting the server:

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

Unlike Windows 10, where you can install a WSL distribution directly from the store, WSL on Windows Server requires that you download a prepared WSL distro. WSL on Windows Server 2019 supports the following Linux distributions:

  • Ubuntu 18.04 and Ubuntu 16.04

  • Debian GNU/Linux

  • Kali Linux

  • OpenSUSE Leap 42

  • SUSE Linux Enterprise Server 12

  • Fedora Remix for WSL

You can download these distributions from the locations listed in Table 18-1.

Table 18-1 Obtaining WSL distributions

Distribution

Location

Ubuntu 18.04

https://aka.ms/wsl-ubuntu-1804

Ubuntu 16.04

https://aka.ms/wsl-ubuntu-1604

Debian GNU/Linux

https://aka.ms/wsl-debian-gnulinux

Kali Linux

https://aka.ms/wsl-kali-linux-new

OpenSUSE Leap 42

https://aka.ms/wsl-opensuse-42

SUSE Linux Enterprise Server 12

https://aka.ms/wsl-sles-12

Fedora Remix for WSL

https://github.com/WhitewaterFoundry/WSLFedoraRemix/releases/

You can download distributions from the addresses listed in Table 18-1 using curl.exe, which is included with Windows Server 2019. For example, to download a distribution to Ubuntu 18.04, use the following command:

Curl.exe -L -o Ubuntu.zip https://aka.ms/wsl-ubuntu-1804

This will download a compressed version of the distribution to the Ubuntu.zip file. Once the distribution archive has been downloaded, extract it to the directory that you wish to have host the distribution files using the Expand-Archive PowerShell cmdlet. For example, to extract Unbuntu.zip, run this PowerShell command:

Expand-Archive .Ubuntu.zip .Ubuntu

It’s a good idea to extract the distribution files in an obvious place, such as a folder named C:Distros, as shown in Figure 18-1.

This figure shows the extracted Ubuntu distribution installation files in the C:distrosUbuntu folder.

Figure 18-1 Extracted distribution

Once the archive has been unzipped, change into the distribution directory and run the distribution launcher application. This will be named <distro>.exe. Running this executable will set up the distribution. You’ll need to set a new UNIX username and password as a part of this process. Once you’ve signed in, you’ll be able to perform typical Linux administration activities. Figure 18-2 shows the output of the lsb_release -a command in Windows Subsystem for Linux.

This figure shows the output of the lsb_release -a command in Windows Subsystem for Linux.

Figure 18-2 Running Ubuntu on Windows Server

You can install multiple Linux distributions on the same Windows Server computer as long as the distributions are in separate directories. You can also run different distros concurrently.

When you run a WSL distribution, the Windows file system will be located in the /mnt/<drive letter> folder, as shown in Figure 18-3.

This figure shows the directory listing output of the Windows file system from within WSL.

Figure 18-3 Windows file system directory listing output

Once WSL is installed, you can run Linux utilities directly from the Windows Server command line by using the wsl.exe <command> syntax. For example, Figure 18-4 shows the output of the ps -aux command.

This figure shows a list of processes running within WSL.

Figure 18-4 List of WSL processes

WSL 2.0

WSL 2.0 is a newer version of Windows Subsystem for Linux that uses virtualization to enable WSL to interact with a Linux kernel, which leads to better performance. Unlike WSL 1, which uses a translation layer to allow Linux workloads to run on Windows, WSL 2 leverages virtualization to host a lightweight kernel to achieve this goal.

WSL 2 requires that the host supports virtualization. If you want to install WSL 2 on a Windows Server 2019 virtual machine, the virtual machine will need to be configured to support nested virtualization. At the time of writing, you can only use WSL 2 on a preview release of Windows Server available through the Windows Server Insider’s program.

In addition to the steps outlined earlier, you’ll need to run the following commands and then restart the computer to enable WSL 2.0 on Windows Server.

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

To ensure that all future WSL distributions use WSL 2.0 instead of WSL, run the following command:

Wsl --set-default-version 2

You can verify which Linux version your WSL distributions are configured for by using the following command, as shown in Figure 18-5.

Wsl --list –verbose
Figure shows a list of WSL distributions and versions.

Figure 18-5 List of WSL distribution versions

If the wsl --list --verbose command does not function on a Windows Server computer, that version of the operating system does not support WSL 2.0.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.37.196