Pages

Running Xfce Desktop on Kali Linux (WSL)

You can create a Windows batch file for automatically starting a Linux GUI desktop in WSL (Windows Subsystem for Linux) along with X410. The following shows how this can be done and also demonstrates how you can pin that batch file to Windows Start or taskbar.

STEP 1 Install a Linux GUI desktop

There are various GUI desktops for Linux. In this example, we'll be installing Xfce4 on Kali Linux (WSL). Kali Linux already has a Xfce4 installation package (kali-desktop-xfce) prepared by Kali Linux team. Hence you simply need to execute the following commands from a Kali Linux WSL console to install Xfce4 desktop.

sudo apt update && sudo apt -y upgrade
sudo apt -y install kali-desktop-xfce



STEP 2 Create a batch file for Windows

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



• x410.exe /desktop

x410.exe launches X410. When "/dektop" is passed as a command line argument, X410 is launched in "Desktop" mode. If X410 is already running in "Windowed Apps" mode, it'll be shutdown and started again in "Desktop" mode.

If you want to launch X410 in "Windowed Apps" mode, you should use the "/wm" command line argument. If you don't specify either argument, X410 will be in the same mode as the last time it was used.

• $(pidof xfce4-session)

"pidof xfce4-session" Linux command returns the process ID of running xfce4-session (Xfce4 Session Manager). Hence the if [ -z \"$(pidof xfce4-session)\" ]; then ensures executing the following commands (i.e., export DISPLAY=...) only when the Xfce desktop isn't already running.

Please also note that the "xfce4-session" doesn't have an '&'. If you append an '&' (i.e., xfce4-session&), it'll be pushed to background and the kali.exe will be terminated immediately. Such termination also terminates the GUI apps running in background as their parent Bash shell (= internally launched by the kali.exe) has exited.

Thus in order to prevent such terminations and keep the Xfce desktop running, you should not append an '&'.

• pkill '(gpg|ssh)-agent'

When xfce4-session is launched, it automatically tries to start ssh-agent and gpg-agent.

Those agents can still be running even after terminating the xfce4-session. In order to terminate the agents since they are no longer needed or used, pkill '(gpg|ssh)-agent'; is added.

If you want to stop xfce4-session from ever launching those agents, you can use the following commands:

xfconf-query -c xfce4-session -p /startup/ssh-agent/enabled -n -t bool -s false
xfconf-query -c xfce4-session -p /startup/gpg-agent/enabled -n -t bool -s false






When you close X410, xfce4-session also gets terminated along with the batch command window and WSL.


Automatically Closing X410 When You Logout

When you select the 'Logout' menu from Xfce desktop, it only terminates the Xfce; X410 will be remained open. If you want to automatically terminate X410 as well, you can use the 'taskkill' command. The 'taskkill' is a Windows command, but since we're in WSL, we can also use it from the Linux shell. So instead of adding it directly to the batch file, we can add it after the 'pkill' command:

Kali Linux.bat
start /B x410.exe /desktop
kali.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;"




Hiding the Batch Command Window

You cannot completely hide the batch command window. However, you can minimize the window by creating a shortcut:


Pin a Batch file to Start and/or Taskbar

You cannot pin a batch file in Windows 10 (yet?). However, there is a workaround. Instead of creating a shortcut for the batch file, create a shortcut for the cmd.exe (Windows Command Prompt) and pass the batch file as its command line argument with '/C' (= carries out the command and terminates). For example, instead of "C:\Users\choung\Desktop\Kali Linux.bat", set the 'Target' as %windir%\system32\cmd.exe /C "C:\Users\choung\Desktop\Kali Linux.bat". Once the Target is changed, you can 'Pin to Start' or 'Pin to taskbar' from its right-click popup menu.

You can also use the method described in the following post for hiding the Console window and pinning the batch file:

Creating a Windows Shortcut for Linux GUI Desktop (WSL)

  • Windows 10 April 2018 Update (1803)
    was used while preparing this post

Once you've managed to successfully start a Linux GUI desktop environment, you can create a Windows shortcut that can be pinned to Start or taskbar.

STEP 1 Find a Linux command line for your GUI desktop

Each Linux GUI desktop has its own startup executable and you need to find it along with its required command line arguments for WSL.

For example, you can use the following command line to launch the Xfce4 desktop on Ubuntu 18.04:

export DISPLAY=127.0.0.1:0.0; xfce4-session;







STEP 2 Create a folder for WSL related scripts and assets

It can be any folder on any drive, but for the sake of simplicity, let's create it on C: drive and name it 'wsl': c:\wsl. If you've decided to use a different folder path, please make adjustments accordingly in the next steps.

We're using a VBScript file to launch the actual batch file that sets up and starts the Linux GUI desktop. You can of course directly launch the batch file. However, we're primarily using the VBScript in order to hide the Command Prompt window that pops up whenever a batch file is executed.

STEP 3 Create a Windows batch file (*.bat) for launching your Linux GUI desktop

C:\wsl\start-linux-desktop.bat
REM ### Start X410 in Desktop Mode
start /B x410.exe /desktop

REM ### Start Linux GUI desktop
ubuntu1804.exe run "<command-to-launch-gui-desktop>"



Replace the "<command-to-launch-gui-desktop>" with the command you found in Step 1. Since the batch can be executed multiple times, you should wrap the command with an "if" statement.

For example, if you're using the Bash shell on Ubuntu, you can use its "pidof"; it returns the process ID of its command line argument. So when you're launching the Xfce4 desktop, you can check for the "xfce4-session" binary and prevent accidently launching it multiple times.

if [ -z "$(pidof xfce4-session)" ]; then export DISPLAY=127.0.0.1:0.0; xfce4-session; fi;



You can also automatically close X410 when the Xfce4 desktop is terminated by using the "taskkill.exe" command from Windows. So the full batch file for launching the Xfce4 desktop becomes:

C:\wsl\start-ubuntu-xfce-desktop.bat
start /B x410.exe /desktop
ubuntu1804.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;"



"pkill '(gpg|ssh)-agent';" is added to terminate the 'gpg-agent' and 'ssh-agent' that are automatically launched by xfce4-session. You can of course permanently disable them from Xfce4 and remove the "pkill '(gpg|ssh)-agent';".

Please note that the "ubuntu1804.exe" is a unique executable alias for launching Ubuntu 18.04. If you also installed Kali Linux and want to run your command from that setup, you need to use "kali.exe". To find out the executable aliases for currently installed WSL distributions, go to Windows Settings » "Apps" » "Apps & features" » "Manage app execution aliases".

STEP 4 Create a VBScript file for executing a batch file without any flashing Console window

C:\wsl\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



Please note that the above VBScript automatically attaches the ".bat" file extension to its first argument and executes it as if it's a batch file in the same folder.

STEP 5 Create a Windows shortcut

For the location of the item, you should enter the following:

wscript.exe "C:\wsl\bat-launcher.vbs" "<batch-file-name>"



Please replace the "<batch-file-name>" with your batch file created in Step 3. For example, if your batch file is named "start-ubuntu-xfce-desktop.bat", you need to enter the following for the shortcut:

wscript.exe "C:\wsl\bat-launcher.vbs" "start-ubuntu-xfce-desktop"



Please note that you must not specify the ".bat" file extension and the batch file must exist in the same folder as the "bat-launcher.vbs" (i.e., 'C:\wsl' in this example).

If you want to change the icon for the shortcut, right-click the icon and select [ Properties ] » "Change Icon".

Installing Pantheon Desktop on Ubuntu (WSL)

Pantheon is the default desktop environment for the elementary OS (http://elementary.io/). However, you can also use it with Ubuntu 18.04 / WSL.

Comparing to Xfce4, Pantheon is sluggish with its default settings due to its gala window manager; gala tries to use 3D effects for its window related animations but unfortunately WSL and X410 currently cannot accommodate its attempts to use 3D graphic hardware acceleration. However, you can still adjust its configuration and make it useable with X410.

STEP 1 Install Pantheon

The official Ubuntu repositories don't include Pantheon desktop. You need to add a PPA maintained by the Pantheon developers (https://launchpad.net/~elementary-os) and install it from there.

sudo add-apt-repository ppa:elementary-os/stable
sudo apt update

sudo apt install elementary-desktop




STEP 2 Remove unused or unsupported UI component packages

When the Pantheon desktop package is installed, it also adds various components that are unsupported or unnecessary in WSL. They only delay the startup time and consume additional memory. You can remove those components by executing the following command:

sudo apt purge gnome-screensaver \
switchboard-plug-power switchboard-plug-bluetooth switchboard-plug-networking \
wingpanel-indicator-bluetooth wingpanel-indicator-network



STEP 3 Launch Pantheon

export DISPLAY=127.0.0.1:0.0; gala --x11& plank& wingpanel&






When you first click the top left 'Applications' menu, there will be a significant delay (1+ minutes). It seems the delay comes from the Pantheon desktop trying to update its application list by browsing through the folders (if you know a way to speed this up, please let us know). However, once the application list is populated, there will be only minimal delays. You should also turn off the window animations in order to further minimize the delays: [ Applications ] » [ System Settings ] » [ Universal Access ] » 'Animations'

If you're using a HiDPI screen and want to scale the desktop, you can use the GDK_SCALE environment variable as the Pantheon desktop is based on GTK+ 3.

export DISPLAY=127.0.0.1:0.0; export GDK_SCALE=2; gala --x11& plank& wingpanel&




If you want to create a Windows shortcut for launching the Pantheon desktop, you can follow the steps described in the post below:

The following shows a batch file example that starts the Pantheon desktop on Ubuntu 18.04:

C:\wsl\start-ubuntu-pantheon-desktop.bat
start /B x410.exe /desktop
ubuntu1804.exe run "if [ -z \"$(pidof plank)\" ]; then export DISPLAY=127.0.0.1:0.0; gala --x11& plank& wingpanel; taskkill.exe /IM x410.exe; fi;"



If you enabled PulseAudio, you can also add it to the batch file.

C:\wsl\start-ubuntu-pantheon-desktop.bat
start /B x410.exe /desktop
start "" /B "C:\wsl\pulseaudio\bin\pulseaudio.exe" -D
ubuntu1804.exe run "if [ -z \"$(pidof plank)\" ]; then export DISPLAY=127.0.0.1:0.0; export PULSE_SERVER=tcp:127.0.0.1; gala --x11& plank& wingpanel; taskkill.exe /IM x410.exe; taskkill.exe /IM pulseaudio.exe /T /F; fi;"




When the sound is not enabled, you'll constantly see the error message "** (wingpanel:190): WARNING ... Volume-control.vala:478: pa_context_connect() failed: Connection refused". You can fix this by completely uninstalling the sound indicator:

sudo apt remove wingpanel-indicator-sound






Please note when you install the Pantheon desktop, it sets the system wide default theme for GTK+ 3 to "elementary". So if you change the mode for X410 to Windowed Apps and start launching individual apps, you'll get the "elementary" theme. But it seems there are compatibility issues when it's used without the Pantheon desktop; a thick black frame is shown for some app windows.

If you're seeing such black frame, you can change the system wide default theme by editing the '/etc/gtk-3.0/settings.ini' file, or create a local settings file (~/.config/gtk-3.0/settings.ini) with a different theme.

~/.config/gtk-3.0/settings.ini
[Settings]
gtk-theme-name = Default



Customizing Xfce Desktop for Ubuntu (WSL)

Once you have Ubuntu and X410 installed from Microsoft Store, you're ready to run Linux GUI apps.

X410 supports two display modes: Desktop and Windowed Apps. In this example, we'll be using the Desktop mode as it gives more immersive and genuine Linux GUI experience.

STEP 1 Install Xfce desktop environment

There are numerous desktop environments for Linux. However, it seems Xfce provides the most hassle free experience for WSL. To install Xfce, execute the following command lines:

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




STEP 2 Create a batch file for launching X410 and Xfce

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



For more information about creating a batch file, please visit:
Running Xfce Desktop on Kali Linux (WSL)

STEP 3 Double-click the batch file and start Ubuntu

If you want to create a Windows shortcut for launching the Xfce desktop, you can follow the steps described in the post below:


Is your Xfce4 crashing when closing an app like gedit?

If you're experiencing such crashes, try launching "xfce4-session" directly from WSL command prompt after manually starting X410 in Desktop mode. You should then be able to examine the warning and error messages generated from Xfce4 components.

If you're seeing a "Got disconnected from D-Bus" message from xfce4-session just before Xfce4 crashes, try the following batch file.

start-ubuntu-xfce-desktop.bat
start /B x410.exe /desktop
ubuntu1804.exe run "if [ -z \"$(pidof xfsettingsd)\" ]; then export DISPLAY=127.0.0.1:0.0; xfsettingsd --sm-client-disable; xfwm4 --sm-client-disable & xfce4-panel --sm-client-disable & xfdesktop --sm-client-disable; pkill '(gpg|ssh)-agent'; fi;"




This batch file launches Xfce4 without its Session Manager (xfce4-session) hence it should effectively prevent the crashes. But, since there is no Session Manager running, you'll get the following error message box when you try to use the "Log Out" menu. When you want to close Xfce4 desktop, simply close X410 instead of using that menu.

Please note that "D-Bus" related errors are caused from the binaries running in WSL. The errors seem to occur while communicating among those binaries via D-Bus and they don't seem to be affected by or related to X410.



Customizing Xfce Desktop

In case you're curious about the theme and icons used for transforming the default Xfce to something like the above screenshot, here are the ingredients:

1. Adapta Theme

If you're using Ubuntu 18.04 (Bionic), you can install the theme from its official PPA repository:

sudo add-apt-repository -y ppa:tista/adapta
sudo apt update
sudo apt install adapta-gtk-theme



For Ubuntu 16.04 (Xenial), you need to download and install a *.deb package file. The last known working version can be installed with the following command lines:

wget https://launchpad.net/~tista/+archive/ubuntu/adapta/+files/adapta-gtk-theme_3.93.0.11-0ubuntu1~xenial1_all.deb
sudo apt install ./adapta-gtk-theme_3.93.0.11-0ubuntu1~xenial1_all.deb




You can share Windows fonts with Ubuntu. But if you want to install the Roboto and Noto fonts mentioned in Adapta theme, you can install them via Ubuntu packages:

sudo apt install fonts-roboto
sudo apt install fonts-noto



After installing the theme, you need to change the following options:

  • [ Applications ] » [ Settings ] » [ Appearance ] » [ Style ] » Adapta-Noto
  • [ Applications ] » [ Settings ] » [ Window Manager ] » [ Style ] » Adapta-Noto

2. Papirus Icons

Papirus team has their official Launchpad repository and their icons can be installed from that PPA. However, installing Papirus icons takes unexpectedly too long (20+ minutes) in WSL. Hence we recommend directly downloading and installing the icons from a *.deb package. It still takes long time to install but Ubuntu won't try to upgrade the icons every time Papirus team publishes a new package (which happens quite often).

For example, after locating a package from the Launchpad page:

wget https://launchpad.net/~papirus/+archive/ubuntu/papirus/+files/papirus-icon-theme_20180512-2389+pkg18~ubuntu14.04.1_all.deb
sudo apt install ./papirus-icon-theme_20180512-2389+pkg18~ubuntu14.04.1_all.deb



If you really want to use the PPA:

sudo add-apt-repository -y ppa:papirus/papirus
sudo apt update
sudo apt install papirus-icon-theme



To remove the PPA:

sudo add-apt-repository --remove ppa:papirus/papirus






3. Tilix Terminal Emulator

There are an endless number of terminal emulators for Linux. Tilix is used for this example as we wanted to try something new. If you're using Ubuntu 18.04 (Bionic), an official Tilix package is already available:

sudo apt install tilix



To Install it on Ubuntu 16.04 (Xenial), you need to use a PPA:

sudo add-apt-repository -y ppa:webupd8team/terminix
sudo apt update
sudo apt install tilix




4. Background image

Tips and Tricks

• Remove / Disable Screensaver

Xfce assumes it's running on a real machine hence it tries to enable power saving features such as screensaver. But in fact those features interfere with the actual power saving functions of Windows. You can completely remove the screensaver by executing the following command:

sudo apt purge xscreensaver




• Adding a startup terminal

If you want to open a terminal when Xfce desktop loads up, you can add an item for launching a terminal in [ Applications ] » [ Settings ] » [ Session and Startup ].