When you install a full desktop version of Ubuntu, you'll get a customized variant of GNOME Shell as your default DE (Desktop Environment). That Ubuntu DE is integrated with various daemons and services running in its underlying Ubuntu OS.

We prepared the following steps to start the same Ubuntu DE that you would find in a full Ubuntu desktop system. But, unfortunately, WSL2 is only a lightweight virtual machine, and you cannot have all those background processes running like a full Ubuntu OS (ex. systemd). Hence, you may not be able to access all Ubuntu settings or run certain apps (ex. GNOME Calendar). But you should surely experience the same Ubuntu graphical user interface.

You must properly configure DISPLAY environment variable in order to use any graphical application or desktop via X410. For more detailed information about setting up the variable for X410, please read the following post.

Using X410 with WSL2
DONE

Ubuntu desktop requires to use D-Bus and those buses may get automatically started by the desktop itself. But such approach can cause issues as it differs from how such buses are configured in a full Ubuntu desktop system.

We prepared the following guide for configuring D-Bus in WSL2 that creates communication buses similar to the ones available in a full Ubuntu desktop system.

Sharing D-Bus among WSL2 Consoles
DONE

There are other Ubuntu desktop packages (ex. ubuntu-desktop), but ubuntu-gnome-desktop package seems to be more compatible with WSL2 and includes many popular software packages (ex. LibreOffice) you would find in a full Ubuntu desktop system.

Before installing ubuntu-gnome-desktop, you should first update apt and upgrade installed packages if necessary.

sudo apt update && sudo apt -y upgrade



Then install ubuntu-gnome-desktop. ubuntu-gnome-desktop includes LibreOffice and it might display warning messages and show some glitches; additionally installing default-jre and libreoffice-java-common should solve those issues.

sudo apt install ubuntu-gnome-desktop default-jre libreoffice-java-common




DONE

Some apps running in an Ubuntu desktop assume certain directories are already available and behave strangely if they don't exist. The following command creates those common directories.

mkdir -p ~/Desktop ~/Documents ~/Downloads ~/Music ~/Pictures ~/Public ~/Videos



You should also create a ~/bin directory and put your scripts and tools there for cleaner file management. If you're using a default .profile login script, ~/bin is also automatically added to your search PATH, hence you can run those executables in ~/bin directory from any location.

mkdir ~/bin




~/.profile
...
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi
...




DONE

In order to run Ubuntu desktop, some environment variables need to be set specifically for the Ubuntu desktop. Instead of just setting those environment variables within a desktop launching script, we prepared the following that can be included in ~/.bashrc and shared among Linux GUI apps even when they are running in X410 Windowed Apps mode; by sharing those environment variables, you can have consistent look-and-feel of the Ubuntu desktop even in Windowed Apps mode.

~/.bash_ubuntu_desktop
# X410 WSL2 Helper
# https://x410.dev/cookbook/#wsl
# --------------------
# Setting up essential environment variables for Ubuntu desktop
# --------------------

# Ubuntu default desktop (GNOME Shell variant)
# https://wiki.gnome.org/Projects/GnomeShell

export XDG_CURRENT_DESKTOP=ubuntu:GNOME
export XDG_SESSION_DESKTOP=ubuntu
export DESKTOP_SESSION=ubuntu
export GNOME_SHELL_SESSION_MODE=ubuntu

# Commonly referenced environment variables for X11 sessions
# https://specifications.freedesktop.org/basedir-spec/latest/

export XDG_CONFIG_DIRS=/etc/xdg/xdg-ubuntu:/etc/xdg
export XDG_DATA_DIRS=/usr/share/ubuntu:/usr/local/share:/usr/share:/var/lib/snapd/desktop
export XDG_MENU_PREFIX=gnome-

export XDG_SESSION_TYPE=x11
export XDG_SESSION_CLASS=user




DONE
if [ -f ~/.bash_ubuntu_desktop ]; then
    . ~/.bash_ubuntu_desktop
fi



You can either use ~/.profile or ~/.bashrc for adding the commands shown above. We recommend using ~/.profile since the default ~/.bashrc exits immediately if Bash was not invoked for an interactive session. The following post has more information about Bash login scripts.

Where should I add my DISPLAY environment variable?
DONE

After installing the package in Step 3, you will notice additional services are added to Ubuntu/WSL2. You can check the available Ubuntu services by executing the following command.

service --status-all



Not all newly added services need to be started in order to use Ubuntu desktop. However, we recommend starting at least network-manager service. While running your Linux GUI apps, check their error/warning messages and see if you need to start additional services.

For automatically starting services, you can use the login script mentioned in Step 2; ~/.bash_sysinit. For example, in order to start network-manager service, add the following line after starting dbus service.

sudo service network-manager start



You should also consider starting at-spi-bus-launcher. It starts an accessibility bus that makes use of D-Bus. Without this daemon you may get a 'Couldn't connect to accessibility bus...' warning when you start modern Linux GUI apps.

/usr/libexec/at-spi-bus-launcher --launch-immediately &



If you don't want to start this daemon and suppress the waring message, you can export NO_AT_BRIDGE=1 and disable using the accessibility bus altogether.

export NO_AT_BRIDGE=1



~/.bash_sysinit
...
export XDG_RUNTIME_DIR=/run/user/$(id -u)
if [ ! -d "$XDG_RUNTIME_DIR" ]; then
{
    sudo_autopasswd

    # Create user runtime directories
    sudo mkdir $XDG_RUNTIME_DIR && sudo chmod 700 $XDG_RUNTIME_DIR && sudo chown $(id -un):$(id -gn) $XDG_RUNTIME_DIR

    # System D-Bus
    sudo service dbus start

    # --------------------
    # Start additional services as they are needed.
    # We recommend adding commands that require 'sudo' here. For other
    # regular background processes, you should add them below where a
    # session 'dbus-daemon' is started.
    # --------------------

    # Network Manager
    sudo service network-manager start

    sudo_resetpasswd
}
fi

set_session_dbus()
{
    local bus_file_path="$XDG_RUNTIME_DIR/bus"

    export DBUS_SESSION_BUS_ADDRESS=unix:path=$bus_file_path
    if [ ! -e "$bus_file_path" ]; then
    {
        /usr/bin/dbus-daemon --session --address=$DBUS_SESSION_BUS_ADDRESS --nofork --nopidfile --syslog-only &

        # --------------------
        # More background processes can be added here.
        # For 'sudo' requiring commands, you should add them above
        # where the 'dbus' service is started.
        # --------------------

        # Accessibility bus
        /usr/libexec/at-spi-bus-launcher --launch-immediately &

    }
    fi
}
...





DONE

You *must* now shutdown WSL and open a new Ubuntu console.

wsl.exe --shutdown







Once WSL is restarted, you should have all the environment variables ready when you open a new Ubuntu console; DISPLAY, DBUS_SESSION_BUS_ADDRESS, XDG_CURRENT_DESKTOP etc.

If you prefer directly opening individual Linux GUI apps and seamlessly use them side by side with Windows apps, you can stop here and ignore the next Step 9 and 10. You simply now need to set X410 in Windowed Apps mode and launch your apps directly from any Ubuntu console. Your Linux GUI apps should show up like Windows apps in similar colors and themes as they would in an Ubuntu desktop.

DONE

You're about to start Ubuntu desktop and X410 must also be in its Desktop mode.

Before launching Ubuntu desktop for the first time, you should execute the following command and disable the animation in Ubuntu desktop; animations in Ubuntu desktop can slowdown overall responsiveness. You only need to execute this command once as Ubuntu desktop remembers it even after WSL2 is restarted.

gsettings set org.gnome.desktop.interface enable-animations false




You can directly start the desktop by executing gnome-shell. But we recommend creating a script for launching the desktop; it should be easier for you to modify it later and add extra commands (ex. launching X410 instead of using its auto start option).

touch ~/bin/start-desktop.sh && chmod 700 $_ && vi $_



start-desktop.sh
#!/bin/bash

if [ -z "$DISPLAY" ]; then
    echo "Error: DISPLAY environment variable is not set."
    exit
fi

gnome-shell




DONE
start-desktop.sh 2>/dev/null &




DONE

Share This Story, Choose Your Platform!