Xfce4 Desktop Environment and X Server for Ubuntu on WSL 2

The Windows Subsystem for Linux 2 is the first time Microsoft will ever ship a full Linux kernel supporting native system calls with Windows 10. Since CEO Satya Nadella took the helm from Steve Ballmer with the mission of making Microsoft a “devices and services company” and the vision of making Windows the best environment to develop for any platform, the historical animosity between Microsoft and the open source community has all but thawed.

The original Windows Subsystem for Linux (WSL), released in 2016, added a Bash shell and the ability to run a user space based on Ubuntu, openSUSE, SUSE Enterprise Linux, Debian, or Kali Linux within Windows. However no true Linux kernel was running on the operating system. The Linux system calls were translated into Windows system calls by Microsoft’s emulation layer.

The WSL was met with much fanfare by developers who wanted to test and compile Linux applications on Windows, as it meant they could use GNU tools and utilities without dual-booting or a VM. Compared to a VM, the WSL had near-native CPU performance with the exception of file system I/O. Since WSL did not have a true Linux kernel, Linux applications running in WSL were bottlenecked by the Windows hooks for handling file metadata, which were much slower than native Linux filesystems. Moreover, some applications had compatibility problems because the kernel services they depended on were not available.

Windows Subsystem for Linux 2 (WSL2) launched for Fast Ring users enrolled in the Windows Insider Program in May 2019. It ships with a full Linux kernel that is open source, and instead of relying on kernel emulation, WSL2 is a utility VM that runs atop of Windows. Doesn’t a VM mean that WSL2 will suffer a performance penalty like running a Linux VM on Windows using Hyper-V? To address this, Microsoft conceived WSL2 as a highly optimized VM using a subset of Hyper-V features, that delivers near-native CPU and filesystem I/O performance. So far most beta testers have observed that WSL2 performance is comparable to WSL1.

With the native Linux kernel, WSL2 boasts near-native filesystem performance which led Docker to announce that its upcoming version of Docker for Windows will leverage WSL2 instead of the Moby Linux VM it currently relies on to run Linux containers within Hyper-V. No longer will you be waiting for Docker for Windows to have its VM booted up. According to Docker, WSL2 and the Docker daemon launches in 2 seconds on their development laptops, meaning WSL2 can launch at the same time a container is started (instead of at bootup). As an added benefit, bind mounts from a container to the Windows host will no longer rely on a Samba service, but be natively handled by WSL2 with much better performance.

Installing WSL2 does not require Hyper-V to be enabled, only Windows Subsystem for Linux and Virtual Machine Platform in Windows optional features. As long as you’re running Insider Preview build 18917 or higher, you’ll see these features available — including on Windows 10 Home.

Although WSL2 is intended as a command line tool for developers, a desktop environment can be run inside WSL2 and you can use an X Server for Windows such as Xming or VcXSrv to listen for X11 (graphical) programs in Linux. Xfce4 is a lightweight desktop environment that developers have been able to get working with both WSL and WSL2.

WSL2 requires Insider Preview build 18917 and above. We used build 18922.

To check your current running build version of Windows, open a Powershell window and run the command winver. If the build number is > 18917, you’re ready to go.

Next, open an Administrator Powershell Window and run the following commands.

Enabling each feature requires a reboot, so save all work and close other applications.

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

Next open the Microsoft Store and install your choice of distribution. We went with Ubuntu 18.04 LTS but you can pick any distribution compatible with WSL.

Once the download is complete, open the Ubuntu shell from the Start Menu to finish installing Ubuntu. You’ll be prompted to provide a Linux username and password. Initially, WSL will be running under WSL1, the original version which does not leverage the new features.

Now open a Powershell window and run the following commands.

The first command lists the installed WSL distributions of Linux, and the second command converts Ubuntu from WSL1 to WSL2. The third command is optional, if you want all future WSL distros installed to use WSL2 features by default.

wsl --list --verbose
wsl --set-version Ubuntu-18.04 2
wsl --set-default version 2

Once done converting, listing the WSL distributions again should say that it’s version 2.

If the WSL conversion to version 2 failed with an error message such as “Conversion failed” or “Error 0x03a001a The requested operation could not be completed due to a virtual disk system limitation. Virtual disk files must be uncompressed and unencrypted and must not be sparse.”, try checking the following.

  • Reboot the system.
  • Virtualization extensions, such as Intel VT-x or AMD-V must be enabled in your BIOS.
  • Compression and encryption must be disabled for the Ubuntu AppData folder (see Github Issue #4103). The path will look something like this.

%localappdata%\Packages\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc

Right click this folder and click Properties from the context menu. Then, click the “Advanced” button beside Attributes. Make sure “Compress contents to save disk space” and “Encrypt contents to secure data” are both unchecked

Try converting the distribution to version 2 again and the operation should succeed.

Now open the WSL shell again from the Start Menu (the Ubuntu app).

Notice that the kernel running is the Microsoft Linux kernel.

Linux hostname 4.19.43-microsoft-standard #1 SMP Mon May 20 19:35:22 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

Use the ifconfig Linux command to find the LAN address of the virtual network adapter for the WSL2 virtual machine. In our particular case, it was 192.168.104.109. This is the Ubuntu network address.

Then, open a Powershell window and run the ipconfig Windows command. In our particular case, it was 192.168.104.97. This is the Windows network address for the vEthernet adapter used for communicating with the Ubuntu VM.

In the WSL shell, use the apt package manager to install the xfce4 desktop environment.

sudo apt-get update && sudo apt-get upgrade -y
sudo apt-get install xfce4

Next, create an entry in the .bashrc file which tells graphical applications at what address to find the locally running X server. Append the following to the last line of the file, using the nano text editor (where 192.168.104.97 is the address of the Windows vEthernet adapter)

nano .bashrc

export DISPLAY=192.168.104.97:0

Save & exit then use the following command to reload .bashrc.

source ~/.bashrc

Now download and install the VcXSrv X server for Windows.

Once installed, launch VcXSrv using the “XLaunch” entry in the Start Menu.

We suggest using the following settings to configure VcXSrv.

Display settings: One large window
How to start clients: Start no client
Disable access control: Yes

Once complete, click “Finish” to launch the X server. If prompted by Windows Firewall, be sure to allow connections to VcXSrv from both Public and Private networks.

Double click the X icon in the system tray to bring VcXSrv into the foreground.

For now you will see a black screen because no graphical X11 apps are running in Linux yet.

Reopen the Ubuntu shell and run the command startxfce4.

The default web browser does not work, but you can install Firefox by opening up a Terminal window and typing sudo apt-get install firefox. Once Firefox is installed, you can launch it using the window manager from the Applications menu.

Featured Image Credit: Larry Ewing (Tux Penguin)

Linux, Virtualization, Windows 10
Previous Post
Using AWS Certificate Manager with Route 53 and ELB for Free SSL Certificates
Next Post
CloudFlare Alternatives & Multi-CDN Options for DDoS Protection

10 Comments.

  • I’m running Ubuntu 18.04.3 on Windows 10 Insider Build 18956 using WSL2. After following these steps, I get the following output when I run “startxfce4”:

    /usr/bin/startxfce4: Starting X server
    /usr/lib/xorg/Xorg.wrap: Only console users are allowed to run the X server
    xinit: giving up
    xinit: unable to connect to X server: Connection refused
    xinit: server error

    The VcXSrv window is still black. Any ideas what I should do?

  • Now I get:

    /usr/bin/startxfce4: Starting X server X.Org X Server 1.19.6
    Release Date: 2017-12-20
    X Protocol Version 11, Revision 0
    Build Operating System: Linux 4.4.0-148-generic x86_64 Ubuntu
    Current Operating System: Linux LAPTOP-HK10G6NK 4.19.57-microsoft-standard #1 SMP Wed Jul 3 20:47:25 UTC 2019 x86_64
    Kernel command line: initrd=\initrd.img panic=-1 pty.legacy_count=0 nr_cpus=4
    Build Date: 03 June 2019 08:10:35AM
    xorg-server 2:1.19.6-1ubuntu4.3 (For technical support please see http://www.ubuntu.com/support) Current version of pixman: 0.34.0
    Before reporting problems, check http://wiki.x.org
    to make sure that you have the latest version.
    Markers: (–) probed, (**) from config file, (==) default setting,
    (++) from command line, (!!) notice, (II) informational,
    (WW) warning, (EE) error, (NI) not implemented, (??) unknown.
    (==) Log file: “/var/log/Xorg.0.log”, Time: Mon Aug 12 08:23:05 2019
    (==) Using system config directory “/usr/share/X11/xorg.conf.d”
    (EE)
    Fatal server error:
    (EE) no screens found(EE)
    (EE)
    Please consult the The X.Org Foundation support
    at http://wiki.x.org
    for help.
    (EE) Please also check the log file at “/var/log/Xorg.0.log” for additional information.
    (EE)
    (EE) Server terminated with error (1). Closing log file.
    xinit: giving up
    xinit: unable to connect to X server: Connection refused
    xinit: server error

  • I am also getting the same error. Here is the details

    /usr/bin/startxfce4: Starting X server

    X.Org X Server 1.19.6
    Release Date: 2017-12-20
    X Protocol Version 11, Revision 0
    Build Operating System: Linux 4.4.0-148-generic x86_64 Ubuntu
    Current Operating System: Linux DESKTOP-63CNOI3 4.19.57-microsoft-standard #1 SMP Wed Jul 3 20:47:25 UTC 2019 x86_64
    Kernel command line: initrd=\initrd.img panic=-1 pty.legacy_count=0 nr_cpus=8
    Build Date: 03 June 2019 08:10:35AM
    xorg-server 2:1.19.6-1ubuntu4.3 (For technical support please see http://www.ubuntu.com/support)
    Current version of pixman: 0.34.0
    Before reporting problems, check http://wiki.x.org
    to make sure that you have the latest version.
    Markers: (–) probed, (**) from config file, (==) default setting,
    (++) from command line, (!!) notice, (II) informational,
    (WW) warning, (EE) error, (NI) not implemented, (??) unknown.
    (==) Log file: “/var/log/Xorg.0.log”, Time: Tue Aug 20 22:42:02 2019
    (==) Using system config directory “/usr/share/X11/xorg.conf.d”
    (EE)
    Fatal server error:
    (EE) no screens found(EE)
    (EE)
    Please consult the The X.Org Foundation support
    at http://wiki.x.org
    for help.
    (EE) Please also check the log file at “/var/log/Xorg.0.log” for additional information.
    (EE)
    (EE) Server terminated with error (1). Closing log file.
    xinit: giving up
    xinit: unable to connect to X server: Connection refused
    xinit: server error

  • This is what I get when I try to run “sudo startxfce4”

    Fatal server error:
    (EE) parse_vt_settings: Cannot open /dev/tty0 (Input/output error)
    (EE)
    (EE)
    Please consult the The X.Org Foundation support
    at http://wiki.x.org
    for help.
    (EE) Please also check the log file at “/var/log/Xorg.0.log” for additional information.
    (EE)
    (EE) Server terminated with error (1). Closing log file.
    xinit: giving up
    xinit: unable to connect to X server: Connection refused
    xinit: server error

    I noticed when I looked at ipconfig in power shell it didn’t list a vethernet (wsl) ip address.

  • DISPLAY with uppercase solved my problem

  • Also, alternative to do the .bashrc “export DISPLAY=192.168.104.97:0” I would recommend doing the line as “export DISPLAY=:0.0” withough the double quotes and in the Xlaunch application to select 0 in the display number, not -1.

  • Excellent. Everything worked !
    Installed 2 hours ago, OS Build 18985.1; also show 13 Sep version in lower bottom of Win10 desktop screen.

    1. I read about $ sudo apt install ubuntu-wsl, which went fine:
    https://www.omgubuntu.co.uk/2019/07/ubuntu-wsl-metapackage-install

    (I did this just before the DISPLAY command. )

    But it doesn’t seem to give me any additional options. The default Chrome browser doesn’t come up and I just installed Firefox as instructed (can’t test it until xfce4 comes back as in #2 issue.)

    2. I brought up the xfce4 window, but when I closed it, and went back to WSL $ startxfce4, it says X server is running already… but VcXsrv remains dark and I don’t know how to bring back Ubuntu+ xfce4 !
    ———
    silicon@DESKTOP-VDKIRMJ:~$ startxfce4
    /usr/bin/startxfce4: X server already running on display 172.18.176.1:0
    Authorization required, but no authorization protocol specified
    xrdb: Resource temporarily unavailable
    xrdb: Can’t open display ‘172.18.176.1:0’
    Authorization required, but no authorization protocol specified
    Authorization required, but no authorization protocol specified
    xfce4-session: Cannot open display: .
    Type ‘xfce4-session –help’ for usage.
    ———–
    3. Once all works as above pointers, is there a way to just bring up xfce4 without typing and clicking, by just clicking on the VcXserv icon in taskbar?

    4. Also will I have to install Nautilus if I want access to C drive from xfce4? I would like to keep all my files on Win 10 C:\ drive, as in my previous dual boot scenario !

    Cheers,
    Great JOB !

  • Hello.

    I am trying your tutorial here, and I believe I had done something similar in the past, however I am getting that
    “/usr/bin/startxfce4: X server already running on display -ip-“.

    Any tips?

  • Sorry, me again. I worked it out! Thanks. It was all my fault.

Comments are closed.