XFCE on Windows System for Linux

First actual post! Here goes.

The intent here is to go from a new-ish Windows 10 installation to a fully featured Windows Subsystem for Linux (WSL) desktop. In my case, after years of using a VM to launch linux into a GUI, I have to admit this is a breath of fresh air. It launches quickly and exits cleanly.

It’s not without its warts…thus far I don’t have sound working, and you unfortunately won’t get the full gamut of Ubuntu applications working. That said, it’s a far cry from traditional virtualization and quite usable on its own. Onward with the howto!

Step 1 – Prerequisite Steps

First, make sure you’re on a supported version of Windows 10. I’m using Windows 10 version 1809, which (I believe) is widely available. I’m also using Windows Home edition. I’m also reasonably certain you must have a 64 bit version of the OS.

OS Settings
Make sure you’re on a version of Windows 10 which supports Windows Subsystem for Linux, as well as a 64 bit version

Next, we need to turn on Developer Mode.

Developer Mode
Turn on “Developer mode” here”

After this, we can turn on the Windows Subsystem for Linux.

WSL in Windows Settings
Make sure the “Windows Subsystem for Linux” box is checked here. I left everything else default

After this, reboot your computer so that it can fully update to enable the selected options.

Once your computer has rebooted, we can use the Microsoft Store to install two pieces of software.

First, we’ll install Ubuntu.

Ubuntu in MS Store
Ubuntu is a free download

I recommend using the non-versioned edition. Keep in mind your executable to launch Ubuntu may be different if you choose a versioned one to install.

Next, I use a piece of software called X410 – I highly recommend using this. It’s worth the expense. Without this, you’ll wind up using some hacky VNC or something similar, with a degraded user experience. I’ll only cover the X410 method here, so if you don’t intend to pay for this software, I’d probably find another blog to continue doing this.

Install X410
This is commercial software, but I highly recommend it for an easy experience. Note that my above hyperlink does not generate any revenue for me

Step 2 – Install and update Ubuntu

From your start menu, launch Ubuntu to finish the installation.

Run Ubuntu to install tools

Once this completes, you’ll be at a bash shell inside of Ubuntu.

After Ubuntu installed

Let’s update and upgrade Ubuntu. First, to update:

sudo apt update

apt update

After that, we can upgrade:

sudo apt upgrade

apt upgrade

Now, you’re fully up-to-date. There are a few ways to utilize things as-is. First off, you can launch “bash” directly from your start menu. You could also manually type “bash” from a Command Prompt. The recommended thing to test is to figure out how your WSL distribution of Ubuntu actually launches – in my case, the executable is called “ubuntu”. You can test this by launching a Command Prompt and typing “ubuntu”. The screenshot below is what happens when you type “bash”.

Testing bash in cmd

Step 3 – Install Xorg and XFCE

Ok, so we have a working Ubuntu WSL configuration. We’ve also installed X410. We have the scaffold up – we just need to install the other components and wire it all together. This step will cover installing the desktop GUI, in this case being XFCE4.

Close Ubuntu if it’s already open, and relaunch it. This is a mostly unnecessary step but it will get us to a clean, recently updated/upgraded starting point. Once you’ve got Ubuntu running, enter the following commands to install the desktop:

sudo apt install xfce4 xfce4-terminal

apt install xfce4

This’ll take a while! Be patient. Once things are done, we can create a batch file and test everything out.

Step 4 – Create quick-launch batch file

First off, let’s create a directory to store all of our WSL related files. I prefer to do this in my home directory, like “C:\Users\<username>\Windows Subsystem for Linux”. Wherever you opt to store these files, make a note of the directory name and full path.

Now, use a text editor to create a batch file, which we’ll save inside of this directory. I recommend notepad++ or Sublime Text. Whichever you decide to use, enter the following text into the editor, and save it into your new directory. It’s vital that the filename ends in .bat for this to work as a quick launch script!

start /B x410.exe /desktop
ubuntu.exe run "if [ -z \"$(pidof xfce4-session)\" ]; then export DISPLAY=127.0.0.1:0.0; xfce4-session; pkill '(gpg|ssh)-agent'; taskkill.exe /IM x410.exe; fi;"

Create and save batch file

Ok, a bit of explanation is in order. Let’s break this down piece by piece. The first line, all we’re doing is firing up X410 and telling i to run in desktop mode.

Next, we’re launching Ubuntu, and giving it special launch commands. Note that in my case, ubuntu.exe is what’s used to launch Ubuntu – in your case, it may be different!

The following conditional – if [ -z \”$(pidof xfce4-session)\” ]; then export DISPLAY=127.0.0.1:0.0; – checks to see if XFCE4 is already running. If it is, we don’t bind it to a virtual display. If it isn’t, we bind it to 127.0.0.1, also known as “localhost”.

Next, we launch XFCE4 with xfce4-session, and it’ll bind to localhost like we’ve already specified. Everything that runs after xfce4-session is actually run after we exit our XFCE desktop.

The first post-shutdown piece of the script – pkill ‘(gpg|ssh)-agent’ – kills the gpg-agent and ssh-agent. This allows XFCE4 to launch cleanly the next time we run our launcher.

Next, we use taskkill.exe /IM x410.exe to kill X410.

Let’s test it! Save the file, in my case I saved it as start-ubuntu-xfce-desktop.bat – all you need to do is double click the file, and you should wind up with this:

First time launching xfce

I selected “Use default config”. Note that to cleanly exit from this desktop, choose XFCE’s “Log out” option. I’m not sure how tolerant this is to just closing with the ‘x’ in the top right, so let’s cleanly exit whenever possible.

Step 5 – Create shortcut to quick launch

Did you notice the ugly command prompt window in the background? I can’t say I’m a big fan of extra windows being open, so let’s create a script that can launch the batch file without creating an extra window. Paste the following into a file, I called mine “bat-launcher.vbs”.

If WScript.Arguments.Count <= 0 Then
    WScript.Quit
End If	

bat = Left(WScript.ScriptFullName, InStrRev(WScript.ScriptFullName, "\")) & WScript.Arguments(0) & ".bat"
arg = ""

If WScript.Arguments.Count > 1 Then
    arg = WScript.Arguments(1)
End If

CreateObject("WScript.Shell").Run """" & bat & """ """ & arg & """", 0, False

Create and save bat launcher

We’ll use wscript.exe to launch this. The way we launch wscript.exe will be with two arguments – the first is the full path to bat-launcher.vbs, the second if the full path to our previously made batch file, but without the .bat ending.

Launch a Command Prompt, cd into the directory (not entirely necessary but a step I do nevertheless), and launch your vbs script with the appropriate arguments:

wscript.exe "C:\Users\ryanf\Windows Subsystem for Linux\bat-launcher.vbs" "start-ubuntu-xfce-desktop"

Note that the path will differ according to your username and/or wherever you decided to make your WSL artifact directory. If everything has gone according to plan, this should launch your XFCE desktop session without the ugly Command Prompt window. If all is good, logout of XFCE as normal.

 

Next, we can make a shortcut to launch your scripts. In the WSL artifact directory, right click and select New -> Shortcut. In the shortcut command, paste whatever it was that you typed previously (the full wscript command). Note that you’ll need the full paths to your bat-launcher.vbs as well as your xfce batch file!

Test this out by double clicking, and you should be good to go! In the next step, I’ll cover making a custom icon, which is totally unnecessary but gives a nice look.

Step 5 – Create custom launch icon

I admit I’m not a huge fan of the default “shortcut” icon. Let’s create a custom one. I’ll give two examples – first is using one bundled in Windows 10, the second will be a custom one we create.

Right click on the shortcut created previously and select Properties.

Shortcut with custom icon

Click the button to change the icon, and browse to C:\Windows\System32\Shell32.dll – this library is packed full of icons.

Shell32 dll for icons

Now, simply find a suitable icon and select it, applying your changes. Good to go!

If you prefer a custom icon, find something on the internet. We’ll need to convert this to a Windows icon file, but in my case converting a png worked fine. I found something interesting at flaticon, by the author freepik. Find the icon you want, and then find a way to convert it. I used a utility called iconconvert, which worked a treat. Convert and save the icon, place it in your WSL artifact directory, and select it as your icon. You can see what I selected below.

Shortcut with custom icon

I’ve also dragged this into my taskbar. Works very well, and looks great, too.

Step 6 – What now?

Now we have a fully working WSL based Ubuntu XFCE desktop. This is great. However, what should we do with it?

In future posts, I’ll explore a bit of theming, potentially getting sound to work (it’s sorta dubious, honestly). Beyond that, I may do a post about doing essentially the same thing with Kali linux, in order to get pentesting tools to run near native on Windows 10.

What next, as for non-WSL things? I’m planning on showing how to install Arch linux on modern hardware, with a self contained bootable external hard drive. I’ll also explore building a custom, fully self-owned VPN. Watch this space, because I’m honestly not sure where I’ll go next, but rest assured I’m always exploring something new.

Cheers

Welcome!

Hi, thanks for reading. First, I suppose a bit of an introduction is in order.

My name is Ryan, I’m a 30-something nerd with a bit of a tinkering hobby obsession. My interests include cars, music, exercise, and technology. This blog will be focused on the latter.

The genesis of this blog came from my appreciation for other tech blogs, which I tend to use most as I acquire new hardware or software. Consider this my attempt to give something back. I hope this helps at least one person, and would love to read your comments.

I’m a very busy person and have difficulty committing, so these posts will be a “best effort” – please don’t get mad at me if something winds up out of date!

Cheers