Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A tutorial to use GUI in WSL2 replacing original XServer by Xvnc, allowing WSL to work like native Linux, including login screen

WSL2 with GUI using Xvnc

In this tutorial, we will setup GUI in WSL2, and access it using VNC. No additional software outside WSL (like VcXsrv) is required, except, of course, a VNC Viewer (RealVNC, TightVNC, TigerVNC, UVNC, etc, all of them might work flawlessly).

The key components we need to install are tigervnc-standalone-server and systemd-genie.

For this setup, I will use Ubuntu 20.04 LTS (Focal Fossa), and install GNOME Desktop. Since the key components aren't bound to Ubuntu or GNOME, you can use your favorite distro and GUI. Check the Sample screenshots section for examples.

So let's go. First, we need a working WSL2 installation.

Before going to real business, let's make sure we are updated.

sudo apt update
sudo apt upgrade

If you are trying to use Debian, you also will need:

sudo apt install curl wget

Now we are ready to go.

Installing components

Installing GUI

  1. Ubuntu has a handy component installer called tasksel, but it's not installed by default. So let's install it.

    sudo apt install tasksel
    
  2. Once we have it installed, let's run it.

    sudo tasksel
    
  3. At the package list, select your favorite GUI package. Use spacebar to select the package, and Tab to confirm your choice. I selected Ubuntu Desktop. The installation will take a while, so be patient.

Installing VNC Server

Pretty easy, one command and you are done:

sudo apt install tigervnc-standalone-server

Installing dotnet-runtime

systemd-genie requires dotnet-runtime, but it ins't installed automatically. Follow the install instructions. Here are the commands to install dotnet-runtime-5.0 on Ubuntu 20.04 LTS (Focal Fossa):

wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb
sudo apt update
sudo apt install dotnet-runtime-5.0

If you are using Debian, the commands are almost the same:

wget https://packages.microsoft.com/config/debian/11/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb
sudo apt update
sudo apt install dotnet-runtime-5.0

Installing systemd-genie

Now we will install systemd-genie, which is responsible for turning the minimalist WSL into a more complete Linux instance, with systemd and other related stuff. This is necessary to run GDM (GNOME Display Manager) and LightDM properly, giving the user a full graphic interface experience, with login and everything. Here are the install instructions. As of April 6th, 2021, these following commands are needed to install it (and I only guarantee they will work Ubuntu and Debian. For other distros, you must check how to get the appropriate package for your system):

sudo apt install apt-transport-https
sudo wget -O /etc/apt/trusted.gpg.d/wsl-transdebian.gpg https://arkane-systems.github.io/wsl-transdebian/apt/wsl-transdebian.gpg
sudo chmod a+r /etc/apt/trusted.gpg.d/wsl-transdebian.gpg
source /etc/os-release
cat << EOF | sudo tee /etc/apt/sources.list.d/wsl-transdebian.list
deb https://arkane-systems.github.io/wsl-transdebian/apt/ $VERSION_CODENAME main
deb-src https://arkane-systems.github.io/wsl-transdebian/apt/ $VERSION_CODENAME main
EOF
sudo apt update
sudo apt install systemd-genie

The installation process is finally done.

Configuring the environment

Creating VNC Server passwords

  1. In this setup, each user has a different VNC password. So you have to configure at least three passwords, one for the current user, other for root, and other for gdm, who whill present the login screen. If you don't configure the password, you won't able to access the login screen, or the user's desktop. First, let's configure the VNC password current user:

    vncpasswd
    
  2. Now, let's configure the VNC password for root (needed if you use LightDM instead GDM):

    sudo -H vncpasswd
    
  3. Finally, let's configure the VNC password for GDM (you need to skip this step if you didn't install GNOME):

    sudo -H -u gdm vncpasswd
    

    Tip: In Debian, the GDM user is Debian-gdm.

    You can repeat the process for other existing users.

Replacing default X by Xvnc

By default, the display manager call multiple X instances, one for each user session, including the login screen, provided by gdm. So we will replace Xorg script by a new version which calls Xvnc instead the classic X/Xorg. This IS the real magic we are trying to do.

  1. First, let's backup the original Xorg script.

    sudo mv /usr/bin/Xorg /usr/bin/Xorg_old
    
  2. Then, we create a new Xorg script.

    sudo nano /usr/bin/Xorg_new
    
  3. Paste the following content in the editor (remember, WSL shell uses CTRL + SHIFT + V for pasting, instead our traditional CTRL + V key combination):

    #!/bin/bash
    for arg do
      shift
      case $arg in
        # Xvnc doesn't support vtxx argument. So we convert to ttyxx instead
        vt*)
          set -- "$@" "${arg//vt/tty}"
          ;;
        # -keeptty is not supported at all by Xvnc
        -keeptty)
          ;;
        # -novtswitch is not supported at all by Xvnc
        -novtswitch)
          ;;
        # other arguments are kept intact
        *)
          set -- "$@" "$arg"
          ;;
      esac
    done
    
    # Here you can change or add options to fit your needs
    command=("/usr/bin/Xvnc" "-geometry" "1024x768" "-PasswordFile" "${HOME:-/root}/.vnc/passwd" "$@") 
    
    systemd-cat -t /usr/bin/Xorg echo "Starting Xvnc:" "${command[@]}"
    
    exec "${command[@]}"
    

    Please note the resolution of the virtual screen. You can change that to fit your needs (1366x768, 1920x1080, etc). Also, you can change the -PasswordFile option to point to a fixed location instead the home of current user, so you don't need to have a password for each user.

  4. Finally, we set the correct permissions for the file and create a link to it:

    sudo chmod 0755 /usr/bin/Xorg_new
    sudo ln -sf Xorg_new /usr/bin/Xorg
    

    Attention: sometimes, system updates replace Xorg link with the original version. Just repeat this step if this happens, and Xvnc will work again as Xorg replacement.

Running systemd-genie

Finally, it's time to put everything together.

genie -s

If you are using Debian, you need one extra step:

echo "LANG=en_US.UTF-8" | sudo tee -a /etc/default/locale

Doing this is like booting Linux again, this time with systemd. Because of systemd, gdm will start automatically, and will create a X instance to display the login interface. We changed this process to make it create Xvnc instances, so we can access them. The first instance will listen to port 5900, the second instance will listen to port 5901, and so on.

Attention: When running genie for the first time, it will take a lot of time, and probably will show an error message. After that, you must check what systemd units have failed. You can check that with a systemctl list-units --failed, then you must check this page to see what to do with each failed unit. Most of them can be simply disabled/masked with no harm or side effects, and after doing that, genie will start much faster and without any error messages.

Accessing the VNC screen

After a while (usually 30 seconds, but it can take more if you don't have a SSD, maybe one minute or two), you can test if it's working properly. Use your favorite VNC Viewer to connect to your localhost port 5900. Use the VNC password set for user gdm. The login screen must appear.

After logging in, the screen will be blank. This is because a new instance of Xvnc was created for user desktop, listening to port 5901. Connect to this screen now. The logged user's desktop must appear. When you log out, the screen at port 5900 will show the login interface again. This applies to GDM (which is the case if you installed Ubuntu Desktop). You can change this behavior changing the configuration file like this:

  1. sudo nano /etc/gdm3/custom.conf

  2. Uncomment and edit the following lines:

     AutomaticLoginEnable=true
     AutomaticLogin=[your username without the brackets]
    

If you are using LightDM, the desktop screen will appear in port 5900, so there's no need to connect to port 5901.

Shutting down

One important thing is: once you start systemd services, you cannot just stop your Linux instance. You must perform a standard Linux shutdown. You can do one of one alternatives below:

  • Power off option on GUI menu
  • sudo init 0, inside the genie bottle
  • genie -u, outside the genie bottle

After doing that, you can safely shut down your WSL instance, either by wsl --terminate or wsl --shutdown. Not doing the shutdown process may cause damage to your WSL instance. So be careful.

Tips and tricks

  • VNC is a very adaptive protocol, and by default tries to use the most aggressive compression available, for better networking performance. But in our case, doing this only adds unnecessary CPU extra load, since you are connecting to localhost ("infinite" bandwith, near zero ping). To remove all compression algorithms and reduce lagging, force your VNC Viewer to connect using RAW encoding. The performance gain is noticeable, specially when playing videos (not a spectacular performance in this particular scenario, though).

  • If you are trying to use Debian, you need to do the following or some apps will not launch (at least in Buster):

    echo "LANG=en_US.UTF-8" | sudo tee -a /etc/default/locale
    

Troubleshooting

  1. If it doesn't work at first, try to check your journalctl logs:

    journalctl -b -t /usr/lib/gdm3/gdm-x-session -t /usr/bin/Xorg --no-pager
    

    If you are using Debian, then the command is:

    journalctl -b -t /usr/libexec/gdm-x-session -t /usr/bin/Xorg --no-pager
    

    In the output, you must see what command line was generated for Xvnc, and which error messages appear. Of course, even if it works correctly, you can check the logs just to see what is happening, or for debugging.

  2. You must check if the custom Xorg script was not replaced by the default version of it. If it was the case, just repeat the steps of Replacing default X by Xvnc section.

  3. Check if Xorg is your default display server, not Xephyr or Wayland. If it's not, you must change it to have Xorg as your default display server.

  4. If you are using LightDM, you also need to check logs at /var/log/lightdm (you will need to use sudo to cat files in that directory). The Xvnc output will be in the file /var/log/lightdm/x-0.log.

  5. If you can connect to 59XX ports, but receive an error like Authentication failure: No password configured for VNC Auth, the file $HOME/.vnc/passwd is missing for that particular user (on port 5900, the user is gdm). Try to repeat the steps described in section Creating VNC Server passwords and try to connect again.

  6. If it still doesn't work, you can try to restart WSL. Open a Windows PowerShell command prompt, and execute the following command (don't forget to save everything that is unsaved before, because WSL will shut down completely):

    PS > wsl --terminate <your distro name>
    

    After that, open your distro shell again and repeat the steps of section Running systemd-genie.

Sample screenshots

GDM

GDM

LightDM

LightDM

GNOME

GNOME

KDE

KDE

Xfce

Xfce

Budgie Desktop

Budgie Desktop

Contributors

Thanks to this guys, whose feedback made this tutorial reach the current level of quality and completeness (and it will be more and more complete as more feedback is given).

@tdcosta100
Copy link
Author

tdcosta100 commented Nov 15, 2021

Hi, @mohmedaref1. Please check this page. The best solution is to disable or mask this unit.

@mohmedaref1
Copy link

mohmedaref1 commented Nov 16, 2021

@tdcosta100 ,
I'm sorry, but how do i do that 😅
i managed to get it to work and i get the login screen

2

.
the problem is once i logged in and try to connect to port 5901 i get a black screen it's the right port but why it's a black screen

1

@tdcosta100
Copy link
Author

tdcosta100 commented Nov 16, 2021

@tdcosta100 , I'm sorry, but how do i do that 😅

sudo systemctl mask multipathd.socket

i managed to get it to work and i get the login screen
...
. the problem is once i logged in and try to connect to port 5901 i get a black screen it's the right port but why it's a black screen

You are almost done with your configuration. But now you have to look your log files to find out what's happening. Check the Troubleshooting section. I cannot tell you what's happening without the clues provided by the logs.

@Sampahcokk-dev
Copy link

Sampahcokk-dev commented Nov 17, 2021

$ genie -s
genie: systemd is not supported under WSL 1.

edit:
nvm its because i use wsl 1

@mohmedaref1
Copy link

mohmedaref1 commented Nov 18, 2021

hi again
that's the output for

journalctl -b -t /usr/lib/gdm3/gdm-x-session -t /usr/bin/Xorg --no-pager

-- Logs begin at Thu 2021-11-04 09:28:29 EET, end at Thu 2021-11-18 16:44:01 EET. --
-- No entries --

@mohmedaref1
Copy link

mohmedaref1 commented Nov 18, 2021

i found the problem i have set up this in the .profile so i could automatically connect to display 0 for the xserver and that was the problem

if grep -q WSL2 /proc/version; then
        # execute in the windows to determine its IP address
        DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0.0
else
        # In WSL1 the DISPLAY can be the localhost address
        if grep -q icrosoft /proc/version; then
                DISPLAY=127.0.0.1:0.0
        fi
fi

i removed it and now it works fine

@tdcosta100
Copy link
Author

tdcosta100 commented Nov 19, 2021

@mohmedaref1, that's great! I'm glad you managed to finally make everything work. Your code appears to be a setup for external XServer (VcXsrv, X410, etc). This interferes with your experience with XVNCServer, so you have to setup a separate configuration in order to make everything to work properly.

@spmolnar
Copy link

spmolnar commented Dec 2, 2021

I have Debian with the Xfce4 Desktop installed with WSL2on my Windows 10 Laptop. I followed the steps in the setup without any warnings or errors, but now I'm stumped. I've gotten to the "Accessing the VNC Screen" and can't seem to get any further.

If I try lightdm I get:

comp@DESKTOP-AMVKD7B:~$ sudo lightdm
[sudo] password for comp:

** (lightdm:155): WARNING **: 15:17:16.462: Failed to get system bus: Could not connect: No such file or directory
Failed to get D-Bus connection

So I turned to the troubleshooting section.

comp@DESKTOP-AMVKD7B:~$ journalctl -b -t /usr/libexec/gdm-x-session -t /usr/bin/Xorg --no-pager
-- Journal begins at Thu 2021-12-02 11:41:28 EST, ends at Thu 2021-12-02 11:51:28 EST. --
Dec 02 11:41:28 DESKTOP-AMVKD7B-wsl /usr/bin/Xorg[189]: Starting Xvnc: /usr/bin/Xvnc -geometry 1024x768 -PasswordFile /root/.vnc/passwd :0 -seat seat0 -auth /var/run/lightdm/root/:0 -nolisten tcp tty7

comp@DESKTOP-AMVKD7B:/var/log/lightdm$ sudo cat x-0.log
Failed to create stream fd: No such file or directory

Xvnc TigerVNC 1.11.0 - built 2021-03-22 21:21
Copyright (C) 1999-2020 TigerVNC Team and many others (see README.rst)
See https://www.tigervnc.org for information on TigerVNC.
Underlying X server release 12010000, The X.Org Foundation

Thu Dec 2 11:56:29 2021
vncext: VNC extension running!
vncext: Listening for VNC connections on all interface(s), port 5900
vncext: created VNC server for screen 0

I installed the TightVCN Viewer, which connect, but only gives me a black screen.

Quite frankly, I am beyond my depth. Assistance will be much appreciated.

Thanks in advancd.

@tdcosta100
Copy link
Author

tdcosta100 commented Dec 2, 2021

Hi, @spmolnar.

By your x-0.log, your X server is running ok. You might check your lightdm.log to see if anything is going wrong. You should connect with the password you set at Creating VNC Server passwords section. If your can connect, but screen is black, XVNC is ok but something else is not being loaded correctly. Could you please post your lightdm.log content, so we can figure out what's happening?

@spmolnar
Copy link

spmolnar commented Dec 3, 2021

I was reasonably sure that the problem was with the lightdm. Here is the log you requested.

comp@DESKTOP-AMVKD7B:/var/log/lightdm$ sudo cat lightdm.log
[+0.00s] DEBUG: Logging to /var/log/lightdm/lightdm.log
[+0.00s] DEBUG: Starting Light Display Manager 1.26.0, UID=0 PID=155
[+0.00s] DEBUG: Loading configuration dirs from /usr/share/lightdm/lightdm.conf.d
[+0.00s] DEBUG: Loading configuration from /usr/share/lightdm/lightdm.conf.d/01_debian.conf
[+0.00s] DEBUG: Loading configuration dirs from /usr/local/share/lightdm/lightdm.conf.d
[+0.00s] DEBUG: Loading configuration dirs from /etc/xdg/lightdm/lightdm.conf.d
[+0.00s] DEBUG: Loading configuration from /etc/lightdm/lightdm.conf
[+0.00s] DEBUG: Registered seat module local
[+0.00s] DEBUG: Registered seat module xremote
[+0.00s] DEBUG: Registered seat module unity
[+0.00s] DEBUG: Using D-Bus name org.freedesktop.DisplayManager
[+0.00s] DEBUG: _g_io_module_get_default: Found default implementation local (GLocalVfs) for ‘gio-vfs’
[+0.00s] WARNING: Failed to get system bus: Could not connect: No such file or directory
[+0.00s] DEBUG: Adding default seat
[+0.00s] DEBUG: Seat seat0: Loading properties from config section Seat:*
[+0.00s] DEBUG: Seat seat0: Starting
[+0.00s] DEBUG: Seat seat0: Creating greeter session
[+0.00s] DEBUG: Seat seat0: Creating display server of type x
[+0.01s] DEBUG: Using VT 7
[+0.01s] DEBUG: Seat seat0: Starting local X display on VT 7
[+0.01s] DEBUG: XServer 2: Logging to /var/log/lightdm/x-2.log
[+0.01s] DEBUG: XServer 2: Writing X server authority to /var/run/lightdm/root/:2
[+0.01s] DEBUG: XServer 2: Launching X Server
[+0.01s] DEBUG: Launching process 159: /usr/bin/X :2 -seat seat0 -auth /var/run/lightdm/root/:2 -nolisten tcp vt7 -novtswitch
[+0.01s] DEBUG: XServer 2: Waiting for ready signal from X server :2
comp@DESKTOP-AMVKD7B:/var/log/lightdm$

@tdcosta100
Copy link
Author

tdcosta100 commented Dec 3, 2021

Hmm yes, there is something wrong. Some questions to help the issue clarification:

  1. Do you init your genie environment with genie -s or genie -i? I'm asking because in your posts, the commands are entered outside the genie bottle, and this usually brings some trouble.
  2. After initializing genie, do you try to initialize lightdm manually? Because lightdm starts by itself, you don't need to do anything.
  3. When were at the component installation, did you execute those intended explicitly for Debian instead the intended for Ubuntu?
  4. Can you execute sudo tasksel and post a screenshot of the selected features?

If you can, maybe you should reset your Debian distro and try all steps again.

@spmolnar
Copy link

spmolnar commented Dec 4, 2021

I have uninstalled and reinstalled Debian from the MS Store.

Then I reran the commands in WSL@GUIXvcn-en.

Here are the commands as they were run. There were no error messages. Deviations f from default choices in the script are tabbed. Troubleshooting results are at the end of the log.

sudo apt update && sudo apt upgrade
sudo apt install curl wget
sudo apt install tasksel
sudo tasksel
Debian desktop environment
Xfce
web server
SSH server
laptop

sudo apt install tigervnc-standalone-server
wget https://packages.microsoft.com/config/debian/11/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb
sudo apt update
sudo apt install dotnet-runtime-5.0

sudo apt install apt-transport-https
sudo wget -O /etc/apt/trusted.gpg.d/wsl-transdebian.gpg https://arkane-systems.github.io/wsl-transdebian/apt/wsl-transdebian.gpg
sudo chmod a+r /etc/apt/trusted.gpg.d/wsl-transdebian.gpg
source /etc/os-release
cat << EOF | sudo tee /etc/apt/sources.list.d/wsl-transdebian.list
deb https://arkane-systems.github.io/wsl-transdebian/apt/ $VERSION_CODENAME main
deb-src https://arkane-systems.github.io/wsl-transdebian/apt/ $VERSION_CODENAME main
EOF
sudo apt update
sudo apt install systemd-genie

vncpasswd
no to view-only password
sudo -H vncpasswd
no to view-only password

sudo mv /usr/bin/Xorg /usr/bin/Xorg_old
sudo nano /usr/bin/Xorg_new
sudo chmod 0755 /usr/bin/Xorg_new
sudo ln -sf Xorg_new /usr/bin/Xorg

genie -s
echo "LANG=en_US.UTF-8" | sudo tee -a /etc/default/locale

systemctl list-units --failed
comp@DESKTOP-AMVKD7B-wsl:~$ systemctl list-units --failed
UNIT LOAD ACTIVE SUB DESCRIPTION
0 loaded units listed.

localhost:5900 - TightVNC Viewer
X Authentication reason: Sorry, loopbck connections are not
  enabled

Troubleshooting

  journalctl -b -t /usr/libexec/gdm-x-session -t /usr/bin/Xorg --no-pager 
  comp@DESKTOP-AMVKD7B-wsl:~$ journalctl -b -t /usr/libexec/gdm-x-session -t /usr/bin/Xorg --no-pager

-- Journal begins at Sat 2021-12-04 08:51:43 EST, ends at Sat 2021-12-04 09:01:43 EST. --
Dec 04 08:51:43 DESKTOP-AMVKD7B-wsl /usr/bin/Xorg[198]: Starting Xvnc: /usr/bin/Xvnc -geometry 1024x768 -PasswordFile /root/.vnc/passwd :0 -seat seat0 -auth /var/run/lightdm/root/:0 -nolisten tcp tty7

comp@DESKTOP-AMVKD7B-wsl:/var/log/lightdm$ sudo cat lightdm.log
[+0.00s] DEBUG: Logging to /var/log/lightdm/lightdm.log
[+0.00s] DEBUG: Starting Light Display Manager 1.26.0, UID=0 PID=153
[+0.00s] DEBUG: Loading configuration dirs from /usr/share/lightdm/lightdm.conf.d
[+0.00s] DEBUG: Loading configuration from /usr/share/lightdm/lightdm.conf.d/01_debian.conf
[+0.00s] DEBUG: Loading configuration dirs from /usr/local/share/lightdm/lightdm.conf.d
[+0.00s] DEBUG: Loading configuration dirs from /etc/xdg/lightdm/lightdm.conf.d
[+0.00s] DEBUG: Loading configuration from /etc/lightdm/lightdm.conf
[+0.00s] DEBUG: Registered seat module local
[+0.00s] DEBUG: Registered seat module xremote
[+0.00s] DEBUG: Registered seat module unity
[+0.00s] DEBUG: Using D-Bus name org.freedesktop.DisplayManager
[+0.01s] DEBUG: _g_io_module_get_default: Found default implementation local (GLocalVfs) for ‘gio-vfs’
[+0.02s] DEBUG: Monitoring logind for seats
[+0.02s] DEBUG: New seat added from logind: seat0
[+0.02s] DEBUG: Seat seat0: Loading properties from config section Seat:*
[+0.02s] DEBUG: Seat seat0 has property CanMultiSession=no
[+0.02s] DEBUG: Seat seat0: Starting
[+0.02s] DEBUG: Seat seat0: Creating greeter session
[+0.05s] DEBUG: Seat seat0: Creating display server of type x
[+0.05s] DEBUG: Using VT 7
[+0.05s] DEBUG: Seat seat0: Starting local X display on VT 7
[+0.05s] DEBUG: XServer 0: Logging to /var/log/lightdm/x-0.log
[+0.05s] DEBUG: XServer 0: Writing X server authority to /var/run/lightdm/root/:0
[+0.05s] DEBUG: XServer 0: Launching X Server
[+0.05s] DEBUG: Launching process 195: /usr/bin/X :0 -seat seat0 -auth /var/run/lightdm/root/:0 -nolisten tcp vt7 -novtswitch
[+0.05s] DEBUG: XServer 0: Waiting for ready signal from X server :0
[+0.05s] WARNING: Could not enumerate user data directory /var/lib/lightdm/data: Error opening directory '/var/lib/lightdm/data': No such file or directory
[+0.05s] DEBUG: Acquired bus name org.freedesktop.DisplayManager
[+0.05s] DEBUG: Registering seat with bus path /org/freedesktop/DisplayManager/Seat0
[+0.37s] DEBUG: Got signal 10 from process 195
[+0.37s] DEBUG: XServer 0: Got signal from X server :0
[+0.37s] DEBUG: XServer 0: Connecting to XServer :0
[+0.38s] DEBUG: Seat seat0: Display server ready, starting session authentication
[+0.38s] DEBUG: Session pid=304: Started with service 'lightdm-greeter', username 'lightdm'
[+0.39s] DEBUG: Session pid=304: Authentication complete with return value 0: Success
[+0.39s] DEBUG: Seat seat0: Session authenticated, running command
[+0.39s] DEBUG: Session pid=304: Running command /usr/sbin/lightdm-gtk-greeter
[+0.39s] WARNING: Error getting user list from org.freedesktop.Accounts: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.Accounts was not provided by any .service files
[+0.39s] DEBUG: Loading user config from /etc/lightdm/users.conf
[+0.39s] DEBUG: User comp added
[+0.39s] DEBUG: Creating shared data directory /var/lib/lightdm/data/lightdm
[+0.39s] DEBUG: Session pid=304: Logging to /var/log/lightdm/seat0-greeter.log
[+0.61s] DEBUG: Activating VT 7
[+0.61s] DEBUG: Activating login1 session c1
[+0.62s] DEBUG: Seat seat0 changes active session to c1
[+0.62s] DEBUG: Session c1 is already active
[+0.91s] DEBUG: Greeter connected version=1.26.0 api=1 resettable=false
[+2.24s] DEBUG: Greeter start authentication
[+2.24s] DEBUG: Session pid=431: Started with service 'lightdm', username '(null)'
[+2.25s] DEBUG: Session pid=431: Got 1 message(s) from PAM
[+2.25s] DEBUG: Prompt greeter with 1 message(s)

comp@DESKTOP-AMVKD7B-wsl:/var/log/lightdm$ sudo cat seat0-greeter.log
** Message: 08:51:44.329: Starting lightdm-gtk-greeter 2.0.8 (Nov 4 2020, 16:56:54)
** Message: 08:51:44.330: [Configuration] Reading file: /usr/share/lightdm/lightdm-gtk-greeter.conf.d/01_debian.conf
** Message: 08:51:44.330: [Configuration] Reading file: /etc/lightdm/lightdm-gtk-greeter.conf
Excess arguments.

(lightdm-gtk-greeter:341): Gtk-WARNING **: 08:51:45.897: Drawing a gadget with negative dimensions. Did you forget to allocate a size? (node menubar owner GreeterMenuBar)

(lightdm-gtk-greeter:341): Gtk-WARNING **: 08:52:00.659: Drawing a gadget with negative dimensions. Did you forget to allocate a size? (node menubar owner GreeterMenuBar)

(lightdm-gtk-greeter:341): Gtk-WARNING **: 08:53:00.738: Drawing a gadget with negative dimensions. Did you forget to allocate a size? (node menubar owner GreeterMenuBar)

(lightdm-gtk-greeter:341): Gtk-WARNING **: 08:54:00.825: Drawing a gadget with negative dimensions. Did you forget to allocate a size? (node menubar owner GreeterMenuBar)

(lightdm-gtk-greeter:341): Gtk-WARNING **: 08:55:00.910: Drawing a gadget with negative dimensions. Did you forget to allocate a size? (node menubar owner GreeterMenuBar)

(lightdm-gtk-greeter:341): Gtk-WARNING **: 08:56:00.981: Drawing a gadget with negative dimensions. Did you forget to allocate a size? (node menubar owner GreeterMenuBar)

(lightdm-gtk-greeter:341): Gtk-WARNING **: 08:57:00.065: Drawing a gadget with negative dimensions. Did you forget to allocate a size? (node menubar owner GreeterMenuBar)

(lightdm-gtk-greeter:341): Gtk-WARNING **: 08:58:00.144: Drawing a gadget with negative dimensions. Did you forget to allocate a size? (node menubar owner GreeterMenuBar)

(lightdm-gtk-greeter:341): Gtk-WARNING **: 08:59:00.229: Drawing a gadget with negative dimensions. Did you forget to allocate a size? (node menubar owner GreeterMenuBar)

(lightdm-gtk-greeter:341): Gtk-WARNING **: 09:00:00.315: Drawing a gadget with negative dimensions. Did you forget to allocate a size? (node menubar owner GreeterMenuBar)

(lightdm-gtk-greeter:341): Gtk-WARNING **: 09:01:00.395: Drawing a gadget with negative dimensions. Did you forget to allocate a size? (node menubar owner GreeterMenuBar)

(lightdm-gtk-greeter:341): Gtk-WARNING **: 09:02:00.480: Drawing a gadget with negative dimensions. Did you forget to allocate a size? (node menubar owner GreeterMenuBar)

(lightdm-gtk-greeter:341): Gtk-WARNING **: 09:03:00.561: Drawing a gadget with negative dimensions. Did you forget to allocate a size? (node menubar owner GreeterMenuBar)

(lightdm-gtk-greeter:341): Gtk-WARNING **: 09:04:00.642: Drawing a gadget with negative dimensions. Did you forget to allocate a size? (node menubar owner GreeterMenuBar)

(lightdm-gtk-greeter:341): Gtk-WARNING **: 09:05:00.731: Drawing a gadget with negative dimensions. Did you forget to allocate a size? (node menubar owner GreeterMenuBar)

(lightdm-gtk-greeter:341): Gtk-WARNING **: 09:06:00.809: Drawing a gadget with negative dimensions. Did you forget to allocate a size? (node menubar owner GreeterMenuBar)

(lightdm-gtk-greeter:341): Gtk-WARNING **: 09:07:00.882: Drawing a gadget with negative dimensions. Did you forget to allocate a size? (node menubar owner GreeterMenuBar)

comp@DESKTOP-AMVKD7B-wsl:/var/log/lightdm$ sudo cat x-0.log

Xvnc TigerVNC 1.11.0 - built 2021-03-22 21:21
Copyright (C) 1999-2020 TigerVNC Team and many others (see README.rst)
See https://www.tigervnc.org for information on TigerVNC.
Underlying X server release 12010000, The X.Org Foundation

Sat Dec 4 08:51:43 2021
vncext: VNC extension running!
vncext: Listening for VNC connections on all interface(s), port 5900
vncext: created VNC server for screen 0

comp@DESKTOP-AMVKD7B-wsl:/var/log/lightdm$ sudo /usr/sbin/lightdm

** (lightdm:545): WARNING **: 09:11:19.500: Error getting user list from org.freedesktop.Accounts: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.Accounts was not provided by any .service files
Failed to use bus name org.freedesktop.DisplayManager, do you have appropriate permissions?

@tdcosta100
Copy link
Author

tdcosta100 commented Dec 8, 2021

@spmolnar, I think you are doing everything correct, except you have to run your VNC Client in Windows, not inside WSL. Did you try that? Sorry for the late response.

@spmolnar
Copy link

spmolnar commented Dec 13, 2021

After several reinstallations. I have a working Debian Bullseye Xfce4 Desktop using WSL2 and the RealVNC Viewer. I start it with the following commands after opening Debian:

C:\Users\SPM\AppData\Local\Microsoft\WindowsApps\debian.exe
genie -i > /dev/null &
genie -s
echo "LANG=en_US.UTF-8" | sudo tee -a /etc/default/locale

There is, however, still a bit of a problem. If I close the Desktop using the logout command and then attempt restarting Debian, I get an error message from the VNC Viewer:

"The connection was refused by the computer."

The only solution that I have found is to restart my Laptop. This is not a very satisfactory solution, and Google has not been of help.

Thanks in advance for your reply.

@tdcosta100
Copy link
Author

tdcosta100 commented Dec 14, 2021

@spmolnar, nice! You achieved the most difficult part.

Now you just need to understand how to initialize, shutdown and restart your WSL instance. First of all, if you are going to logout or shutdown your machine, first you need to shutdown your genie environment, either by the Shutdown command inside Xfce, or by genie -u. After that, your WSL instance is still running. You can just logout/shutdown your computer, or you can shutdown all WSL running instances with wsl --shutdown (in Command Prompt or Windows PowerShell).

If you want to start everything again, you need to open your Debian shell (you don't need to execute it directly, you can use the Start Menu shortcut), and start genie again. You can directly call genie -s, it will start first, then will take you inside the bottle.

I hope you will be able to execute the appropriate commands without the need of rebooting your laptop. Tell me if anything goes wrong.

@spmolnar
Copy link

spmolnar commented Dec 14, 2021

@playXE
Copy link

playXE commented Dec 22, 2021

hello, @tdcosta100. Now when WSL2 supports Linux GUI apps natively(https://docs.microsoft.com/en-us/windows/wsl/tutorials/gui-apps) is it possible to install KDE or GNOME desktop and make it as default one?

@tdcosta100
Copy link
Author

tdcosta100 commented Dec 23, 2021

Hi, @playXE. Unfortunately, currently I cannot answer your question, because I don't have Windows 11 yet, and my current laptop doesn't have the hardware WSL2 needs to run GUI apps, if my Windows 10 was in the Insider Preview version.

I bought a new laptop, and then I will be able to answer you, in january/2022. I hope it's fully possible.

@bhatiaabhinav
Copy link

bhatiaabhinav commented Jan 25, 2022

@tdcosta100 Any updates on Windows 11?

@tdcosta100
Copy link
Author

tdcosta100 commented Jan 31, 2022

Hi, @bhatiaabhinav. Nothing yet. My new laptop just arrived a few days ago. I'm conducting some tests, nothing very promising for while.

@andrew521
Copy link

andrew521 commented Feb 20, 2022

Not working for me. Here is what I am getting:

$ genie -s
Waiting for systemd....!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Timed out waiting for systemd to enter running state.
This may indicate a systemd configuration error.
Attempting to continue.
Failed units will now be displayed (systemctl list-units --failed):
UNIT LOAD ACTIVE SUB DESCRIPTION
● systemd-remount-fs.service loaded failed failed Remount Root and Kernel File Systems
● multipathd.socket loaded failed failed multipathd control socket

LOAD = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB = The low-level unit activation state, values depend on unit type.

2 loaded units listed.

@cerebrate
Copy link

cerebrate commented Feb 20, 2022

@tdcosta100
Copy link
Author

tdcosta100 commented Feb 21, 2022

Yes, like @cerebrate pointed, it's a known situation and it already covered at the Running systemd-genie (refers to the page @cerebrate pointed).

@tdcosta100
Copy link
Author

tdcosta100 commented Mar 11, 2022

Hi, guys. Some of you are waiting for my thoughts on WSLg. Well, for now, no good news, and I will explain why.

  1. WSLg is a transparent implementation of Wayland. This means we have, for while, no control or customization over its behavior.
  2. WSLg always displays a launched graphical app in a new window. This prevents desktop shells like gnome-shell from working properly.
  3. Also, we have a problem because GDM cannot launch Xwayland properly. I tried to launch it manually. It works, and I can open gnome-shell there, but still cannot launch apps in that display. Even the welcome app opens in a separate window, making it unusable.

So, if want to see this tutorial fully working in a WSLg-enabled environment, you have to disable it. I think it's not what we really want, specially because we are throwing off the performance, once WSLg uses hardware-accelerated graphics, while this tutorial uses only software rendering.

I'm sorry not having a good solution for now, but I will keep trying to find out a solution. Corrections on my assertions and help finding a viable solution are welcome.

@Billionatoms
Copy link

Billionatoms commented Mar 14, 2022

Hello, Thank you for this method.
I am using Ubuntu on WSLg on Windows 11. Somehow I managed to get a "Ubuntu Login" screen but whenever I try to login, it takes me back to sign in again. Does anybody knows how to resolve this issue?

@tdcosta100
Copy link
Author

tdcosta100 commented Mar 16, 2022

To help you, first we need to understand how did you managed to get your login screen. Reproducing your scenario will help us to improve it, if possible.

@jamesooo
Copy link

jamesooo commented Mar 21, 2022

Looks like it's possible to automatically hook the symlink creation into apt by creating /etc/apt/apt.conf.d/99relink-Xvnc-over-Xorg containing:

# This script will relink Xvnc in case any packages replace Xorg
DPkg::Post-Invoke { "ln -sf /usr/bin/Xorg_new /usr/bin/Xorg";};

Some context around hooks:
https://manpages.debian.org/bullseye/dpkg/dpkg.1.en.html#post
https://manpages.debian.org/bullseye/apt/apt.conf.5.en.html#HOW_APT_CALLS_DPKG(1)

@tdcosta100
Copy link
Author

tdcosta100 commented Mar 30, 2022

Very nice addition, @jamesooo! Thank you!

@deGekata
Copy link

deGekata commented Apr 12, 2022

image
image

Tried guide on newly installed Debian. Ive searched for any similar issues, but havent found anything helpful. Thinking about changing network parameters, because they might been changed by vpn services. Also, I thing i need to somehow mask/disable module, but I dont know how. (Sorry for my poor english).

@tdcosta100
Copy link
Author

tdcosta100 commented Apr 23, 2022

Hi, @deGekata. I'm so sorry for taking so long to give you an answer. To mask a systemd service, you need to do sudo systemctl mask <unit name>. Also, you need to check your logs with journalctl, like described in Troubleshooting section. Maybe there is something wrong with your /usr/bin/Xorg_new script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment