Technology

Windows Subsystem for Linux 2: The GUI features developers have been asking for

Windows Subsystem for Linux 2: The GUI features developers have been asking for

Microsoft’s WSL 2 is getting graphics support. Here’s how to get ready for it.

istock-1127291554.jpg

Change is coming for WSL.

Image: Getty Images/iStockphoto

The Windows Subsystem for Linux (WSL) is an important part of Windows 10. Using a version of Microsoft’s Hyper-V virtualisation technology, it lets you run Linux as if it was part of Windows, sharing resources and files. It was originally designed for developers building web and cloud applications, but it’s turned into something a lot more powerful that brings two very different operating systems together. 

SEE: Kubernetes security guide (free PDF) (TechRepublic)

Microsoft originally designed WSL for use with the bash command line, but it has evolved into something much more akin to a traditional Linux distribution. Instead of using Microsoft’s original set of shims and translations to convert Linux syscalls to Windows calls, it now uses a Microsoft-compiled and supported Linux kernel, initially using the 4.19 kernel release but now rolling out a more up-to-date 5.4. That change has improved support for Linux applications, with most running without need for any changes. There are some issues: as it’s a subsystem it isn’t launched at startup, so there’s no support for timed jobs or for services using systemd. 

Beyond the command line

The command line is great for much of what Microsoft intended Linux on Windows to be used for — testing out code and using local copies of Linux-based cloud-native application stacks — using Windows’ revamped and much-improved Terminal. But developers and users wanted more, finding ways to bring familiar Linux desktops to Windows, using Windows versions of the X servers that add graphics support to most Linux distributions. 

With WSL 1, getting a GUI up and running was a complex process. The changes in WSL 2 to how it handles networking made that even harder, as the Linux virtual machine no longer shared an IP address with the host Windows OS. Instead it’s a VM with shared resources, using a virtual switch to share the host’s network card. That requires scripts to find the current IP address each time you launch WSL and a change to the security model for any Windows X Server. 

wsl-comparison-tr.jpg

Image: Microsoft

WSL 2 and the GPU

Microsoft’s promise of a new GUI model for WSL 2 by the 2020 holiday season has been pushed back, most likely due to a delay in the development of the WSL 2 Mesa 3D OpenGL/DirectX bridge that appears to be key to providing support for Linux graphics without requiring new drivers for all Windows supported graphics cards. If Microsoft and its partners can deliver a way of mapping the Linux OpenGL calls to Windows graphics APIs, it should mean WSL 2 graphics support will work, without requiring any changes to WSL 2-hosted Linux distributions or to Windows. 

With Mesa 3D offering OpenGL APIs to both Windows and Linux from a single set of drivers, it should be possible for Microsoft to deliver a Windows-optimised Wayland server that can be installed from any Linux-distribution repository. All you’d need to do is download the server and a Linux desktop environment. The final part of the equation would be a version of a tool like xrdp to deliver either a full desktop or a set of selected Windows apps to a remote desktop client running on Windows. 

As an aside, it’s interesting to note that Microsoft’s partner in its DirectX/Mesa 3D bridge work, Collabora, recently demonstrated a Wayland compositor that runs on WINE. Work like this could easily be used to add Wayland support into Windows’ Remote Desktop tooling alongside Microsoft’s own RDP protocol. 

Using RDP with WSL 2

You can get a feel for how this would work using the new Ubuntu Community Preview release of Ubuntu’s WSL environment, if you’re using a Dev channel build of Windows 10. The Ubuntu Community Preview isn’t available from a search in the Windows Store: you have to follow a link in the Ubuntu WSL 2 blogs to a hidden page to download it. It’s not hidden for any nefarious reason — it’s currently a version of 20.10 intended for beta testers and is updated regularly (with the next release likely to be a preview of the 21.04 release). As each update will require you to reset the distribution’s WSL 2 environment, it’s not recommended for daily use. 

One of the first tools that the Ubuntu Community Preview is testing is a new out-of-box-experience and a related set of configuration tools. These include the option of preparing Ubuntu for use with WSL 2 networking for GUIs, setting up a script that automatically sets the appropriate DISPLAY environment variables. You can enable this when configuring Ubuntu for the first time, or from the built-in configuration tool. 

A quick way of adding GUI support is to use xrdp, which is easy enough to configure. First use the Ubuntu package manager to install a desktop environment. I chose Kubuntu, but there are many other popular options. This adds many GUI-based applications to WSL, along with a clean, modern desktop environment using Kubuntu’s plasma design language. 

SEE: Microsoft 365: A cheat sheet (free PDF) (TechRepublic)

Installing Kubuntu can take some time, even on a fast PC, as it needs to set up various databases and configuration files as part of an install. Once it’s installed, all you need to do is make a couple of small edits to the xrdp configuration files, changing the RDP port from 3389, and adding better support for PC screens (increasing the colour depth for a better picture) and launch both the dbus message system and xrdp, before using Windows’ Remote Desktop Connection tool to open a display from WSL 2. 

With RDP and Remote Desktop Connection you can share your Windows clipboard with WSL 2, cutting and pasting to terminals running on the Kubuntu desktop. It’s a smooth integration, as WSL 2 on current Insider Dev builds also exposes its ext4 file system to Windows File Explorer. While you do have to have a complete desktop, and you can’t just bring application windows to the Windows desktop, having a full-featured Linux environment like Kubuntu makes it possible to start thinking about cross-platform workflows, and how you can bring the two environments together. 

The future of WSL?

Microsoft’s promised Wayland-based WSL GUI will take a more application-oriented approach to Linux, with early demos showing Linux applications accessible from the Windows desktop, and running in their own Windows. If you use the Azure-based Windows Virtual Desktop you should be familiar with this approach, bringing hosted apps to your desktop while they’re running in Azure. You can think of it as a similar approach to tools like Parallels’ macOS support for Windows, with Windows apps in the macOS Dock. 

WSL 2 is an important component of Windows 10, helping Microsoft bring developers back to Windows PCs. Integrating Linux GUI applications with the Windows desktop should make it even more attractive — especially if it can be delivered seamlessly, without requiring additional hardware-specific drivers. The easier it is, the better. With an intended audience who only want to write code, seamlessly breaking down the barriers between Windows and Linux is essential to its future. 

Also see

Leave a Reply

Your email address will not be published. Required fields are marked *