Nearly a year after it was first announced, Microsoft has finally released a preview of support for graphical apps in the Windows Subsystem for Linux. Shipping with the latest Dev Channel builds of Windows 10, it’s a major upgrade to WSL, showing how future releases will integrate Linux applications with the Windows desktop.

Microsoft is calling this new feature WSLg, installing as an update to its existing WSL 2 platform, and without needing any changes to installed WSL Linux distributions. I tested it with the standard Ubuntu WSL release from the Windows store, using both an existing install and a fresh set-up. (I’d recommend using a fresh setup if you’ve experimented with using an X server or xrdp to add graphics to WSL in the past, as it avoids any confusion with existing scripts and Windows applications.)

What is WSLg?

WSLg is a fascinating piece of engineering. It’s actually a whole new Linux distribution that runs alongside your WSL Linux, adding hooks for video and audio to it, setting environment variables to redirect X and Wayland calls, along with audio. Microsoft has built it on top of its own internal Linux distribution, CBL-Mariner, which is designed to be a minimal Linux for use in containers and on edge devices. It’s an ideal tool for this, providing only the minimum services needed to support the components of WSLg: XWayland, Weston, PulseAudio and FreeRDP. On the Windows side, it adds a plug-in to the Windows RDP client to allow it to deliver application windows without any work on your part.

If you’ve used X11 with WSL you are going to find WSLg a lot easier to get working. There’s no need to install an X Server in Windows (which had to run in an insecure mode to allow WSL 2’s random IP addresses to work) or run scripts to configure networking every time you start WSL. It’s a lot closer to using the xrdp techniques TechRepublic looked at recently, building on Microsoft’s own Remote Desktop Protocol and the developing Linux Wayland user interface technology to deliver Linux applications directly to the Windows desktop.

The intent behind WSLg is that things should just work — that you shouldn’t need to do anything to bring Linux GUIs to the Windows desktop. Code should install in WSL and be available in Windows through WSLg with no additional configuration. On a few hours testing it looks like Microsoft has succeeded: it’s simple to use, and it performs well.

Getting started with WSLg

Installing WSLg is certainly easy enough, once you’ve upgraded to Windows 10 build 21364 or later. From an administrator command line, either in PowerShell or cmd, type ‘wsl –install’ to get going with WSL 2 and WSLg. Next, install a Linux distribution — there are several including Ubuntu in the Windows Store. If you haven’t used WSL before, Ubuntu is a good, well-supported distribution, and has added several WSL-specific features to its Windows Store release. If you’re already running WSL 2 you can upgrade your existing installation with ‘wsl –update’ to add WSLg.

Applications show up in the Windows Start menu, in a folder named after their parent Linux distribution. Microsoft also adds a small Tux overlay to Linux application icons to distinguish them from Windows applications.
Image: Simon Bisson / TechRepublic

It’s also a good idea to install a WSL-aware graphics driver, with versions available from Nvidia, AMD, and Intel. These include support for hardware-accelerated OpenGL, which will speed up display and keep any lag to a minimum. Be prepared for issues setting up one of these graphics drivers in Windows as they are very much beta quality code, and can cause problems. They don’t just provide hooks for OpenGL in Linux, but also add support for GPU programming. This means you can start using WSL for machine-learning development, among other tasks.

Once WSLg is installed and running, you won’t notice any difference from a standard WSL 2 instance. It’s only when you use your Linux distribution’s package manager to install GUI software that you see the first signs of WSLg. Once an application has been installed, WSLg will add it to your Windows Start menu, in a folder under the name of your Linux distribution. You can then launch it just like any Windows application.

Behind the scenes, Windows starts up Linux, launching both your distribution and the WSLg tools. These automatically connect to a remote desktop session that’s set up to host your application, displaying it as if it were a Windows app on the Windows desktop. You can then interact with it using mouse and keyboard like any other Windows app. Alternatively, you can launch a graphical Linux application from the WSL command line.

Under the hood

The architecture of WSLg means that it supports both X and Wayland applications, with PulseAudio for sound support. It’ll use your default sound device, with no need for additional configuration. If you’re using WSL 2 to build and test applications that need sound support, this is a quick and easy way of taking advantage of existing hardware and Windows’ sound support.

Microsoft is developing WSLg in the open, with a public GitHub repository. You can use this to report bugs and issues, as well as build and modify your own versions. Under the hood it’s built around a mix of different open-source components and tools, along with Microsoft’s own code. It builds on the familiar Weston Wayland compositor, working with applications that use Wayland directly and that use XWayland as a bridge between the X11 and Wayland worlds.

SEE: Checklist: Securing Windows 10 systems (TechRepublic Premium)

The bridge between Weston and the Windows desktop is the familiar RDP protocol. Developed to deliver Windows Server desktops on Windows PCs, RDP is built into Windows and, thanks to FreeRDP, it’s part of Weston. Microsoft has been using RDP as part of its Windows Virtual Desktop tools to deliver applications, and has recently added support for these techniques to Windows Defender Application Guard, where a custom Hyper-V hypervisor hosts a Windows VM running either Edge or Office in a secure container. These same techniques deliver Linux applications to Windows rather than a full Linux desktop.

WSLg builds on top of Microsoft’s own CBL-Mariner Linux distribution, running as a system service. You can’t tell that it’s running, as it’s invisible to the WSL management tools, and while you can log into it from a terminal, anything you do inside the distro will be reset next time it reboots, as it launches from a fixed image on every boot. That allows Microsoft to treat WSLg as a fixed system component, so it can update systems by installing a new WSLg virtual machine.

That same Hyper-V hypervisor hosts your WSL 2 instances, so it’s not a big step to go from using those techniques to render WSL. Combined with CBL-Mariner, that means that WSLg has a surprisingly low impact on system resources.

Using WSLg

As WSLg uses Wayland and XWayland, not all Linux GUI applications will work yet (although I’ve yet to find any that won’t), and you may still need to run an X Server or xrdp if you have specific and essential tools that won’t work. Still, it’s an impressive piece of engineering, and as Wayland support improves in Linux it will only get better. You may want to investigate using the latest versions of Mesa3D for better OpenGL support in WSLg, alongside WSLg-ready Windows graphics drivers. Microsoft is encouraging Linux distributions to slipstream them into their WSL releases, so performance will continue to improve.

Mesa3D support should help developers using WSL 2 to port games to Linux, as well as allowing complex Unix CAD applications and other design tooling to use WSLg to work on Windows, without needing a full port.

If you’re worried about application support, we’ve yet to find anything that didn’t work over WSLg. We’ve been able to run Ubuntu desktop tools, classic Unix games like Nethack’s X11 port, Linux games from Steam, a host of different editors and IDEs, the LibreOffice productivity suite, as well as Microsoft’s own Edge browser (using it to stream video and audio). The experience of using Linux applications on Windows is much like running Windows applications on macOS via Parallels.

Applications launch from the Start menu, appearing as standard windows on your desktop. The mouse pointer and window tools do switch to Linux versions in those windows, but that’s only to be expected. Resizing windows is a little laggy, as windows are handled by the Weston Waylond compositor and not Windows. Finally, if an application hangs, you can use the Windows Task Manager to shut them down: they appear as Remote Desktop Connection sessions and can be managed from there.

Microsoft has been working on WSLg for some time, with early builds sent to some developers at the end of 2020. Even so, this is a surprisingly polished release for a preview. The WSLg architecture is well thought-out, working on both high-end workstation-class hardware and on budget education laptops. If you’re a developer who needs to work in both Windows and Linux, and need to build UIs, it’s well worth installing — especially with Linux desktop graphical support coming in future .NET releases.