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. 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
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:

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:

    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 -i > /dev/null &
genie -s

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.

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.

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 -t /usr/lib/gdm3/gdm-x-session -t /usr/bin/Xorg
    

    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. 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.

  3. 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.

  4. 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).

@keepitsane

This comment has been minimized.

Copy link

@keepitsane keepitsane commented Jul 8, 2020

This is super helpful thank you very much! Just a quick question is it possible to display a single GUI application if I don't need the entire Ubuntu Desktop GUI?

@tdcosta100

This comment has been minimized.

Copy link
Owner Author

@tdcosta100 tdcosta100 commented Jul 8, 2020

Hi! Thank you for your feedback! Yes, it's possible to display a single GUI application, and you can use it like a Windows application. There are a lot of tutorials around here, just search for WSL and VcXsrv and you will find plenty of how-tos.

@keepitsane

This comment has been minimized.

Copy link

@keepitsane keepitsane commented Jul 8, 2020

Thanks was just looking into it. So is the new GPU support that windows announce is coming later this year meant to replace solutions like VcXsrv and Xvnc?

@tdcosta100

This comment has been minimized.

Copy link
Owner Author

@tdcosta100 tdcosta100 commented Jul 8, 2020

Yes, I hope so. They are all workarounds because Microsoft doesn't provide an "official" solution that works out of box. I'll be happy if this tutorial becomes obsolete, because Microsoft's Wayland will use GPU capabilities, so graphics performance will be much better than using VcXsrv or Xvnc.

@keepitsane

This comment has been minimized.

Copy link

@keepitsane keepitsane commented Jul 9, 2020

Hey just one last quick question if we want to remove all of this other then uninstalling all the packages are there any recommend steps to revert back?

@tdcosta100

This comment has been minimized.

Copy link
Owner Author

@tdcosta100 tdcosta100 commented Jul 10, 2020

Basically you have to remove all GUI components you installed (there are many tutorials teaching how to do it in a normal Linux distro, should work for WSL as well), remove dotnet-runtime and genie, and then you remove Xorg script and revert the Xorg_old to Xorg. After that, you might have everything like before. I'd rather reset everything, but if you have lots of things installed and configured, the uninstall approach must be enough.

@shepherd1530

This comment has been minimized.

Copy link

@shepherd1530 shepherd1530 commented Jul 10, 2020

Good job. @tdcosta100 I successfully completed the steps above an I am at Ubuntu-desktop login screen but now I am experiencing a loop where I enter the correct password an I am taken back to the login screen.

@tdcosta100

This comment has been minimized.

Copy link
Owner Author

@tdcosta100 tdcosta100 commented Jul 11, 2020

Hi, @shepherd1530. You need to watch the logs. Do the following:

  1. Wait the login screen appear in VNC Viewer. Then in a WSL Shell you type the following: journalctl -f

  2. Put your password and try to login.

  3. After returning to login screen, you can examine the log messages in WSL Shell to see any errors. Something is crashing, so you have first to discover what it is.

@shepherd1530

This comment has been minimized.

Copy link

@shepherd1530 shepherd1530 commented Jul 11, 2020

@tdcosta100 Thanks, I saw something about DISPLAY 0:0 in the logs failing and removing it from my .bashrc fixed it.

@tdcosta100

This comment has been minimized.

Copy link
Owner Author

@tdcosta100 tdcosta100 commented Jul 11, 2020

Great! Thank you for sharing your solution.

@gates17

This comment has been minimized.

Copy link

@gates17 gates17 commented Jul 20, 2020

well i followed this tutorial to the letter only to end up at wsl shell after starting genie. but i just cant connect to gui since i never used vnc. any particular command you have to type?

@tdcosta100

This comment has been minimized.

Copy link
Owner Author

@tdcosta100 tdcosta100 commented Jul 21, 2020

Hi. First you need to download a VNC Viewer. At the beginning of the tutorial you have some links. When you open the VNC Viewer, you connect to localhost:5900. It should ask the password if it's everything ok. After that, you are connected. Then after logging in, you can disconnect and connect to localhost:5901, then your desktop should appear after typing the password.

@DennisWangCW

This comment has been minimized.

Copy link

@DennisWangCW DennisWangCW commented Jul 21, 2020

捕获

hi @tdcosta100 Why I got this message?

@tdcosta100

This comment has been minimized.

Copy link
Owner Author

@tdcosta100 tdcosta100 commented Jul 22, 2020

@DennisWangCW very strange! Did you install Ubuntu Desktop using tasksel? If you did so, you can try running bash under gdm account: sudo -u gdm bash, and then you can cd ~/, and pwd. Check if the directory is /var/lib/gdm3. Also, check the permissions for file /home/1eakycau1dron/.vnc/passwd.

Apparently vncpasswd under gdm is trying to write a file in 1eakyca1dron profile. This can happen if $HOME is being set globally somewhere.

@tdcosta100

This comment has been minimized.

Copy link
Owner Author

@tdcosta100 tdcosta100 commented Jul 22, 2020

@gates17, were you able to connect to VNC with VNC Viewer?

@akhilkathi97

This comment has been minimized.

Copy link

@akhilkathi97 akhilkathi97 commented Aug 7, 2020

After a login I am getting a blank screen.

@tdcosta100

This comment has been minimized.

Copy link
Owner Author

@tdcosta100 tdcosta100 commented Aug 8, 2020

Hi, @akhilkathi97. You need to connect to localhost:5901 after logging in. If you have problems connecting to this screen in particular, please let me know.

@MonicaTiyyagura

This comment has been minimized.

Copy link

@MonicaTiyyagura MonicaTiyyagura commented Aug 27, 2020

I am authentication failure error, when i try to login
[gdm-password][1316]: pam_unix(gdm-password:auth): authentication failure; logname= uid=0 euid=0 tty=/dev/tty1 ruser= rhost= user=<user_name>

@tdcosta100

This comment has been minimized.

Copy link
Owner Author

@tdcosta100 tdcosta100 commented Aug 29, 2020

Hi, @MonicaTiyyagura. If your password is correct, you should try this tutorial in a clean WSL2 installation. Maybe there is something wrong in your current setup.

@jalbarrang

This comment has been minimized.

Copy link

@jalbarrang jalbarrang commented Aug 31, 2020

Hi @tdcosta100, i got a problem where i followed this steps and when finished it finished it broke network connection, can't donwload nor browse through wsl2, any hints?

@tdcosta100

This comment has been minimized.

Copy link
Owner Author

@tdcosta100 tdcosta100 commented Aug 31, 2020

Hi, @jalbarrang. Sometimes it happened with me, I resolved it restarting WSL with wsl --shutdown in PowerShell. If it doesn't work, try to restart your PC. Tell me if it solves your problem.

@vdevan

This comment has been minimized.

Copy link

@vdevan vdevan commented Oct 22, 2020

Debian distribution is updated. The user name gdm doesn't exist anymore. I tried sudo -u gdm vncpasswd and it gave me an error. A quick look at /etc/passwd found at that it Debian-gdm. So for users not able to set vncpasswd please use sudo -u debian-gdm

@tdcosta100

This comment has been minimized.

Copy link
Owner Author

@tdcosta100 tdcosta100 commented Nov 4, 2020

@vdevan, thanks a lot for this information! Did you succeed to make it work?

@Greasy-Monkey

This comment has been minimized.

Copy link

@Greasy-Monkey Greasy-Monkey commented Nov 6, 2020

For debian it should be sudo -u Debian-gdm vncpasswd not sudo -u debian-gdm vncpasswd

@vdevan

This comment has been minimized.

Copy link

@vdevan vdevan commented Nov 6, 2020

@vdevan, thanks a lot for this information! Did you succeed to make it work?

Yes. It works great. I use for both Ubuntu and Debian app. Since the Windows preview release allow you to mount ext4 volume as well, I am able to mount USB HDD from linux to Windows and make a backup

@geev-gv

This comment has been minimized.

Copy link

@geev-gv geev-gv commented Nov 20, 2020

Thank you, I am using Debian
ubu@WINTAB-5FDA1V5-wsl:~$ neofetch _,met$$$$$gg. ubu@WINTAB-5FDA1V5-wsl ,g$$$$$$$$$$$$$$$P. ---------------------- ,g$$P" """Y$$.". OS: Debian GNU/Linux 10 (buster) on Windows 10 x8 ,$$P' $$$. Kernel: 4.19.128-microsoft-standard
',$$P ,ggs. $$b: Uptime: 29 mins d$$' ,$P"' . $$$ Packages: 1377 (dpkg)
$$P d$' , $$P Shell: bash 5.0.3
$$: $$. - ,d$$' Resolution: 1024x768
$$; Y$b._ ,d$P' DE: MATE
Y$$. ."Y$$$$P"' WM: Metacity (Marco)
$$b "-.__ WM Theme: Menta Y$$ Theme: Menta [GTK2/3]
Y$$. Icons: menta [GTK2/3] $$b. Terminal: mate-terminal
Y$$b. Terminal Font: Monospace 13 "Y$b.
CPU: Intel Celeron N2940 (4) @ 1.833GHz
`""" Memory: 399MiB / 3108MiB

ubu@WINTAB-5FDA1V5-wsl:~$
`

@tdcosta100

This comment has been minimized.

Copy link
Owner Author

@tdcosta100 tdcosta100 commented Nov 23, 2020

Hi, @geev-gv. I didn't undersand what you said. Are you having any trouble with the tutorial?

@ptflp

This comment has been minimized.

Copy link

@ptflp ptflp commented Dec 5, 2020

sometime /usr/bin/Xorg file gone, needs to reconfigure like in this tutorial
using ubuntu 20.04 and set auto login, to prevent redudant actions with connecting on second display on port 5901

sudo nano /etc/gdm3/custom.conf

then add or uncomment

 AutomaticLoginEnable=true 
 AutomaticLogin=user1

where user1 your username

@ptflp

This comment has been minimized.

Copy link

@ptflp ptflp commented Dec 5, 2020

is there way use 2 display in vnc?

@tdcosta100

This comment has been minimized.

Copy link
Owner Author

@tdcosta100 tdcosta100 commented Dec 9, 2020

Hmmm I don't know if there is a way to really create 2 displays, but you can create one big display with the twice of the normal width. 3840x1080, for example. Will this solve your problem?

You can also play with Xvfb and x0vnc. With Xvfb you create 2 screens, and with x0vnc you make a way to show them.

Btw, thank you for your tips! In future revisions I will add them, specially Xorg, which I had to reconfigure recently due to updates on XOrg packages.

@gokulyc

This comment has been minimized.

Copy link

@gokulyc gokulyc commented Dec 25, 2020

I am getting below error :

gokulyc@LAPTOP-LC4B480R:~$` sudo mv /usr/bin/Xorg /usr/bin/Xorg_old
gokulyc@LAPTOP-LC4B480R:~$ sudo nano /usr/bin/Xorg
gokulyc@LAPTOP-LC4B480R:~$ sudo chmod 0755 /usr/bin/Xorg
gokulyc@LAPTOP-LC4B480R:~$ genie -s
Failed to create bus connection: No such file or directory
genie: starting shell failed; machinectl shell returned 1.
@tdcosta100

This comment has been minimized.

Copy link
Owner Author

@tdcosta100 tdcosta100 commented Dec 25, 2020

Hi, @gokulyc. Could you please post the output of genie -s -v?

@gokulyc

This comment has been minimized.

Copy link

@gokulyc gokulyc commented Dec 26, 2020

Hi, @gokulyc. Could you please post the output of genie -s -v?

Output:

gokulyc@LAPTOP-LC4B480R:~$ genie -s -v
'-v' was not matched. Did you mean '-h'?
Unrecognized command or argument '-v'

--shell:
  Initialize the bottle (if necessary), and run a shell in it.

...
...
...
...

I have used exact same content in /usr/bin/Xorg , what values should i replace with?
image

Unable to enter username(textbox disabled):

image

@tdcosta100

This comment has been minimized.

Copy link
Owner Author

@tdcosta100 tdcosta100 commented Dec 29, 2020

Hi, @gokulyc. Sorry for the long wait. My genie version was outdated, so I had to upgrade it (and they changed the install procedure - AGAIN). In this current version, I was able to reproduce the same error you had. But despite the error, genie is initializing. You can check this by running genie -s a second time.

About the username greyed out option, it's correct. You can just type the password, not the username. After you enter the password you have set in the vncpasswd phase, the GDM's login screen should appear.

Please tell me if you can log in into GNOME.

And don't forget: after logging in the login screen will be blank, and you will have to connect again, this time to port 5901.

@gokulyc

This comment has been minimized.

Copy link

@gokulyc gokulyc commented Dec 29, 2020

I am still facing issues, I am not much into bash/linux.

image

Bash Output :

gokulyc@LAPTOP-LC4B480R-wsl:~$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: bond0: <BROADCAST,MULTICAST,MASTER> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 2a:d5:eb:d5:ec:49 brd ff:ff:ff:ff:ff:ff
3: dummy0: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 36:7c:54:8c:8b:c7 brd ff:ff:ff:ff:ff:ff
4: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:15:5d:b5:9a:67 brd ff:ff:ff:ff:ff:ff
    inet 172.27.149.60/20 brd 172.27.159.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::215:5dff:feb5:9a67/64 scope link
       valid_lft forever preferred_lft forever
5: sit0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN group default qlen 1000
    link/sit 0.0.0.0 brd 0.0.0.0


gokulyc@LAPTOP-LC4B480R-wsl:~$ sudo vncpasswd
[sudo] password for gokulyc:
Password:
Verify:
Would you like to enter a view-only password (y/n)? n
gokulyc@LAPTOP-LC4B480R-wsl:~$ journalctl -f
-- Logs begin at Fri 2020-12-25 22:30:52 IST. --
Dec 29 13:46:55 LAPTOP-LC4B480R-wsl /usr/lib/gdm3/gdm-x-session[614]:  SConnection: Client needs protocol version 3.8
Dec 29 13:46:55 LAPTOP-LC4B480R-wsl /usr/lib/gdm3/gdm-x-session[614]:  SConnection: Client requests security type VncAuth(2)
Dec 29 13:47:00 LAPTOP-LC4B480R-wsl /usr/lib/gdm3/gdm-x-session[614]: Tue Dec 29 13:47:00 2020
Dec 29 13:47:00 LAPTOP-LC4B480R-wsl /usr/lib/gdm3/gdm-x-session[614]:  SVncAuth:    opening password file '/var/lib/gdm3/.vnc/passwd' failed
Dec 29 13:47:00 LAPTOP-LC4B480R-wsl /usr/lib/gdm3/gdm-x-session[614]:  SConnection: AuthFailureException: No password configured for VNC Auth
Dec 29 13:47:00 LAPTOP-LC4B480R-wsl /usr/lib/gdm3/gdm-x-session[614]:  Connections: closed: 172.27.144.1::49256 (No password configured for VNC Auth)
Dec 29 13:47:00 LAPTOP-LC4B480R-wsl /usr/lib/gdm3/gdm-x-session[614]:  EncodeManager: Framebuffer updates: 0
Dec 29 13:47:00 LAPTOP-LC4B480R-wsl /usr/lib/gdm3/gdm-x-session[614]:  EncodeManager:   Total: 0 rects, 0 pixels
Dec 29 13:47:00 LAPTOP-LC4B480R-wsl /usr/lib/gdm3/gdm-x-session[614]:  EncodeManager:          0 B (1:-nan ratio)
Dec 29 13:47:05 LAPTOP-LC4B480R-wsl WSL2: Performing memory compaction.
@tdcosta100

This comment has been minimized.

Copy link
Owner Author

@tdcosta100 tdcosta100 commented Dec 29, 2020

Hi, @gokulyc. That's a progress, but you have to repeat the steps of the "Creating VNC Server passwords" section. There is no VNC password for the gdm3 user. Tell me if it works after repeating these steps I told you.

@gokulyc

This comment has been minimized.

Copy link

@gokulyc gokulyc commented Dec 31, 2020

Hi, @gokulyc. That's a progress, but you have to repeat the steps of the "Creating VNC Server passwords" section. There is no VNC password for the gdm3 user. Tell me if it works after repeating these steps I told you.

I have re-done from scratch . It working but have connect to 2 times.

"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). If you are using LightDM, the desktop screen will appear in port 5900, so there's no need to connect to port 5901."

how to connect using light dm ? Can you share DM contact?

@tdcosta100

This comment has been minimized.

Copy link
Owner Author

@tdcosta100 tdcosta100 commented Dec 31, 2020

Great, @gokulyc! If you want to change your default display manager do LightDM, first you need to install it with sudo apt install lightdm. Right after the install, you will be prompted to choose the display manager. Choose lightdm and everything will be ok. If you want to change your default display manager again, just execute sudo dpkg-reconfigure lightdm or sudo dpkg-reconfigure gdm3, and choose again what display manager you want to use.

You can also use @ptflp's tips and enable autologin for GDM3. If you do that, you will have a desktop instead a login screen when connecting to VNC port 5900.

@gokulyc

This comment has been minimized.

Copy link

@gokulyc gokulyc commented Dec 31, 2020

Great, @gokulyc! If you want to change your default display manager do LightDM, first you need to install it with sudo apt install lightdm. Right after the install, you will be prompted to choose the display manager. Choose lightdm and everything will be ok. If you want to change your default display manager again, just execute sudo dpkg-reconfigure lightdm or sudo dpkg-reconfigure gdm3, and choose again what display manager you want to use.

You can also use @ptflp's tips and enable autologin for GDM3. If you do that, you will have a desktop instead a login screen when connecting to VNC port 5900.

Done 👍 Thank you.

@ROBYER1

This comment has been minimized.

Copy link

@ROBYER1 ROBYER1 commented Jan 25, 2021

With Ubuntu Home on 20.04 Ubuntu, you can actually make the display stay on Display 1 (localhost 5900 or localhost) by going to Settings>Users>Automatic Login: On

I found this by accident last week and just tested on another machine, now you don't have to start up vnc viewer to go to localhost 5900 first then swap over to 5901 after, you can stay on 5900 👯‍♂️

@tdcosta100

This comment has been minimized.

Copy link
Owner Author

@tdcosta100 tdcosta100 commented Jan 26, 2021

@ROBYER1, you are right. @ptflp pointed that too, but changing settings file instead using the GUI. Thank you for giving this alternative!

@ROBYER1

This comment has been minimized.

Copy link

@ROBYER1 ROBYER1 commented Jan 26, 2021

Any tips on getting this to run with Ubuntu 18.04 LTS? I set this up fine with 20.04 on a PC but I need 18.04 on a separate machine for python 3.6 for Nvidia stuff.. long story but I hit issues with saving the vnc password file and using the genie -s command doesn't work on 18.04 unfortunately

When repeating 'sudo -u gdm vncpasswd', I get:
Couldn't open /home/USER/.vnc/passwd for writing

@tdcosta100

This comment has been minimized.

Copy link
Owner Author

@tdcosta100 tdcosta100 commented Jan 27, 2021

Hi, @ROBYER1. Try the following steps:

  1. sudo -H -u gdm vncpasswd and set the VNC password.
  2. genie -i to start genie. You can safely stop it if it gets stuck on "Waiting for systemd"
  3. genie -s to get inside genie bottle

Tell me if these steps work for you.

@siegLoesch

This comment has been minimized.

Copy link

@siegLoesch siegLoesch commented Feb 3, 2021

Hello tdcosta100,
thank you for your efforts to build and provide this tutorial. I succeded to install Debian Buster with Gnome 3.
The only subject is that I am not able to open a gnome-terminal what I have been worked around for the moment using sakura (that runs fine). The messages after trying to open a gnome terminal are as follows (maybe one of you had a similar experience and a better solution as my current workaround):

Feb 3 14:33:34 localhost org.gnome.Shell.desktop[542]: Xlib: extension "DPMS" missing on display ":0".
Feb 3 14:33:34 localhost gsd-color[690]: could not find device: property match 'XRANDR_name'='VNC-0' does not exist
Feb 3 14:36:45 localhost org.gnome.Terminal.desktop[542]: # Error constructing proxy for org.gnome.Terminal:/org/gnome/Terminal/Factory0: Error calling StartServiceByName for org.gnome.Terminal: Timeout was reached

Siegfried

@tdcosta100

This comment has been minimized.

Copy link
Owner Author

@tdcosta100 tdcosta100 commented Feb 3, 2021

Hi, @siegLoesch. I had to install a Debian distro to understand your problem. I also couldn't open gnome-terminal, and the same error was showing up. So I found this solution and it worked. So try it and tell me if it works for you too.

@siegLoesch

This comment has been minimized.

Copy link

@siegLoesch siegLoesch commented Feb 4, 2021

Hello @tdcosta. Thanks a lot for looking into it. I am currently working from home office and will check it next Monday, when I will back to my office. Please stand by.

@tdcosta100

This comment has been minimized.

Copy link
Owner Author

@tdcosta100 tdcosta100 commented Feb 4, 2021

@siegLoesch, no problem, take your time =)!

@siegLoesch

This comment has been minimized.

Copy link

@siegLoesch siegLoesch commented Feb 5, 2021

@tdcosta100: just tested and I must say worked like a charm! Thank you so much!
I also have to remark that the solution according your tutorial works much better than any I tried before: rdp/xrdp and running a x-server on windows.

@tdcosta100

This comment has been minimized.

Copy link
Owner Author

@tdcosta100 tdcosta100 commented Feb 6, 2021

@siegLoesch, that's very nice to know! I have made some improvements to guide other Debian users, thank your for telling me your problem!

@NoroelleSaeth

This comment has been minimized.

Copy link

@NoroelleSaeth NoroelleSaeth commented Mar 29, 2021

Couldn't get it working with KDE, but overall - awesome tutorial, helped me a lot. Thanks!

@tdcosta100

This comment has been minimized.

Copy link
Owner Author

@tdcosta100 tdcosta100 commented Mar 29, 2021

@NoroelleSaeth, thank you! Could you provide more details of what's happening? Maybe I can help you and improve the tutorial even further.

@adamgranthendry

This comment has been minimized.

Copy link

@adamgranthendry adamgranthendry commented Apr 7, 2021

Does this work with CentOS?

@tdcosta100

This comment has been minimized.

Copy link
Owner Author

@tdcosta100 tdcosta100 commented Apr 8, 2021

Hi, @adamgranthendry. It might work, but maybe you will have some trouble making systemd-genie work in it:

arkane-systems/genie#114

I can't test it by myself, since in Windows Store I will have to pay to download CentOS Distro.

@adamgranthendry

This comment has been minimized.

Copy link

@adamgranthendry adamgranthendry commented Apr 8, 2021

@tdcosta100 Actually, yes you can. You don't have to pay for CentOS. Just download and install your desired version (6, 7, or 8) here. Then install systemd-genie (unzip tarball into root / if necessary). Would you please be able to test?

@tdcosta100

This comment has been minimized.

Copy link
Owner Author

@tdcosta100 tdcosta100 commented Apr 9, 2021

Great, @adamgranthendry!

Here are my steps for CentOS8-Stream (after creating a user and adding it to wheel group, then logging in with it):

Preparing the environment

sudo yum update
sudo yum install epel-release
sudo yum install nano

Installing Components

Installing GUI

sudo yum groupinstall "GNOME" "GNOME Applications"
sudo ln -sf /lib/systemd/system/runlevel5.target /etc/systemd/system/default.target

Installing VNC Server

sudo yum install tigervnc-server

Installing systemd-genie dependencies

sudo yum install dotnet-runtime-5.0 daemonize

Installing systemd-genie

rpm_name=`curl -s https://api.github.com/repos/arkane-systems/genie/releases/latest | grep name | grep rpm | cut -d '"' -f 4`
curl -L https://github.com/arkane-systems/genie/releases/latest/download/$rpm_name --output $rpm_name
sudo yum localinstall $rpm_name

After that, you can follow the remaining steps of the Debian tutorial. Please tell me if it works for you.

@adamgranthendry

This comment has been minimized.

Copy link

@adamgranthendry adamgranthendry commented Apr 9, 2021

@tdcosta100 Thank you so much! A couple things:

  1. At sudo yum localinstall $rpm_name, I get the following output:
Loaded plugins: fastestmirror, langpacks
Examining genie-1.36-1.fc33.x86_64.rpm: genie-1.36-1.fc33.x86_64
Marking genie-1.36-1.fc33.x86_64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package genie.x86_64 0:1.36-1.fc33 will be installed
--> Processing Dependency: systemd-container for package: genie-1.36-1.fc33.x86_64
Loading mirror speeds from cached hostfile
 * base: mirror.sov.uk.goscomb.net
 * epel: mirror.siena.edu
 * extras: uk.mirrors.clouvider.net
 * updates: mirror.sov.uk.goscomb.net
--> Finished Dependency Resolution
Error: Package: genie-1.36-1.fc33.x86_64 (/genie-1.36-1.fc33.x86_64)
           Requires: systemd-container
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest
  1. At sudo -H -u gdm vncpasswd, I get:
sudo: unable to execute /bin/vncpasswd: Permission denied
  1. At genie -s, I get:
Unknown operation shell.
genie: starting shell failed; machinectl shell returned 1.

(genie -i > /dev/null & outputs [1] 589).

  1. I'm not sure how to use VcXsrv XLaunch to view the VNC. (or should I use the Windows Remote Desktop Connection tool?). How do I view the VNC screen?
@adamgranthendry

This comment has been minimized.

Copy link

@adamgranthendry adamgranthendry commented Apr 9, 2021

@tdcosta100 Or maybe on 4 I should use Xming and putty?

@adamgranthendry

This comment has been minimized.

Copy link

@adamgranthendry adamgranthendry commented Apr 9, 2021

@tdcosta100 FYI, I have CentOS 7 installed.

@adamgranthendry

This comment has been minimized.

Copy link

@adamgranthendry adamgranthendry commented Apr 9, 2021

@tdcosta100 Maybe could you show me creating a user, adding to wheel group, and logging in? I've tried:

sudo useradd hendra11
sudo passwd hendra11
sudo usermod -aG wheel root
sudo usermod -aG wheel hendra11

However, when I run

sudo su hendra11

from root, I get

su: failed to execute /bin/bash: Permission denied

I even tried

sudo chmod 755 /
sudo chmod 755 /bin
sudo chmod 755 /lib
@adamgranthendry

This comment has been minimized.

Copy link

@adamgranthendry adamgranthendry commented Apr 9, 2021

@tdcosta100 I can confirm that when I use CentOS 8 Stream, all those errors go away. However, I do the following with VcXsrv:

image

image

image

image

image

image

image

@adamgranthendry

This comment has been minimized.

Copy link

@adamgranthendry adamgranthendry commented Apr 9, 2021

@tdcosta100 Basically, I think I just don't know how to get the VNC screen up...

@adamgranthendry

This comment has been minimized.

Copy link

@adamgranthendry adamgranthendry commented Apr 9, 2021

@tdcosta100 I can't get a VNC viewer to work. Can you help me?

@adamgranthendry

This comment has been minimized.

Copy link

@adamgranthendry adamgranthendry commented Apr 9, 2021

@tdcosta100 I got this to work as follows:

  1. sudo yum install -y xrdp

  2. sudo nano /etc/xrdp/xrdp.ini

    • Change port from 3389 to 3390
  3. sudo systemctl start xrdp

  4. Run Windows Remote Desktop Connection

  5. Connect to localhost:3390

GNOME now opens up!! Thank you!!!

@To-beas

This comment has been minimized.

Copy link

@To-beas To-beas commented Apr 10, 2021

Hi,

I luckily found this thread. And it's alive - that's the best part.

Edit: The next day the setup doesn't work anymore. I can't get ubuntu-desktop to appear anymore. What measures I took:
reinstalling all of .dnet, genie, tigervnc and setup new passwords for vncserver. Having same problom like @gokulyc with genie: (most recent version):

  1. genie -s: can't open shell: Looked into man and --help: running and can't use "genie -u" to stop it because within shell
  2. genie -s: "ipconfig.exe command not found"
    Starts and can go to a desktop similar environment with "vncserver && tigervnc -xstartup /usr/bin/xterm"
@swapansanjay

This comment has been minimized.

Copy link

@swapansanjay swapansanjay commented Apr 14, 2021

Installing systemd-genie has been failing. All the above steps suggested dont work.
Giving up.

@cerebrate

This comment has been minimized.

Copy link

@cerebrate cerebrate commented Apr 16, 2021

@tdcosta100 genie author here. Just a quick note or two:

  1. The first line in

genie -i > /dev/null &
genie -s

isn't actually necessary. The commands to do something inside the bottle (-s, -l, and -c) all initialize the bottle automatically if it hasn't been already. -i exists so that you can get systemd services running without opening a shell/running a command or so that you can preinitialize it to start faster the first time you use one of the others.

  1. If it looks like it's timing out or times out at the "Waiting for systemd...!!!" stage, that means one or more of your systemd units is failing. You should probably fix that, because while the examples I've seen so far are innocuous, there's no guarantee all of them are. Notes on known-to-cause-issues units are available on the genie repo wiki. (1.37, forthcoming, will automatically list them for you to make this process easier.)

  2. It's also a good idea to shut down systemd and its units properly using the shutdown option in your GUI or wsl genie -u from a Windows prompt before terminating the distro or shutting down Windows. While systemd services are robust enough to handle it most of the time, just using wsl --terminate <distro> or wsl --shutdown is in many ways like yanking the power cord on a Linux machine; not to be recommended, no matter how many times you get away with it.

@cerebrate

This comment has been minimized.

Copy link

@cerebrate cerebrate commented Apr 16, 2021

(Also, for those having trouble with CentOS 7 or otherwise having machinectl shell errors: the problem is that since 1.29, genie requires a newer version of systemd and systemd-container (>= 232-25) than your distro has. Gory details here:

arkane-systems/genie#104

The short version of the workaround is to update your distro (if available), update your systemd, or grab 1.28 from the releases page for manual install.)

@adamgranthendry

This comment has been minimized.

Copy link

@adamgranthendry adamgranthendry commented Apr 16, 2021

@tdcosta100 If I have a GUI program in GNOME I want to run and it is giving me an error

Error: Unable to initialize gtk, is DISPLAY set properly?

How can I fix this? I have tried adding export DISPLAY=local:0.0 to my runcom file (.zshrc) within GNOME and then re-sourcing (i.e. source ~/.zshrc), but this does not work. I am using xrdponlocalhost:3390`.

@adamgranthendry

This comment has been minimized.

Copy link

@adamgranthendry adamgranthendry commented Apr 16, 2021

@tdcosta100 FYI, I ran

loginctl list-sessions

which gave

SESSION  UID USER     SEAT  TTY 
     c3    0 root               
     c4   42 gdm      seat0 tty1
     c5 1000 hendra11           

Then, running

loginctl show-session -p Display -p Active c5

showed

Display=:10 Active=yes

and in fact, I have Display=:10 listed when I run printenv. However, exporting this in ~/.zshrc with

export DISPLAY=:10

and then resourcing

source ~/.zshrc

does not fix the problem.

Any thoughts?

@tdcosta100

This comment has been minimized.

Copy link
Owner Author

@tdcosta100 tdcosta100 commented Apr 17, 2021

Hi, guys. I'm sorry being silent for so many days. I'm having serious issues with my Internet provider, so I was unable to test everything and answer your questions in a reasonable time. But I will answer what is possible with my bad mobile connection.

@tdcosta100

This comment has been minimized.

Copy link
Owner Author

@tdcosta100 tdcosta100 commented Apr 17, 2021

@adamgranthendry, wow, so many issues. But let's address them all:

  1. I tried very hard to make systemd-genie to work properly in CentOS7. Unfortunately, there are some dependencies in the latest version which prevent it to be properly installed, and it's not usable because it requires some component versions that are not avaliable to CentOS7. So you have to try the 1.28 version, which was pointed by @cerebrate. In my research, I also arrived on the discussion pointed by @cerebrate (arkane-systems/genie#141), and I think it's the only possible current workaround if you want to use systemd-genie. There are other options to run systemd in a container, but they are beyond the scope of this tutorial.

  2. My steps to create a user in CentOS7 right after running it for the first time (the user is called "user1"):

    useradd user1
    passwd user1
    usermod -a -G wheel user1
    

    Then I exited the shell and used this command:

    CentOS7 config --default-user user1
    

    After that, my user was able to sudo and everything.

  3. You tried to use VcXsrv, but the purpose of this tutorial is not to use such a thing (and X410, or any other external X Server). You also don't need to use PuTTY. With a VNC Viewer, you just connect to port 5900/5901 and get a full GUI. Of course, after everything is correctly set-up. Using XRDP is a good alternative to this tutorial, but if you use it, you don't need to follow the steps of this tutorial. It's redundant, or maybe it will interfere in your XRDP setup, so it's not productive to use both solutions unless you know enough about them both to not mess up with them. If XRDP works for you, keep with it, there is no need to use my solution. And that's ok, because a good solution is a solution which fit your needs =).

@tdcosta100

This comment has been minimized.

Copy link
Owner Author

@tdcosta100 tdcosta100 commented Apr 17, 2021

Hi,

I luckily found this thread. And it's alive - that's the best part.

Edit: The next day the setup doesn't work anymore. I can't get ubuntu-desktop to appear anymore. What measures I took:
reinstalling all of .dnet, genie, tigervnc and setup new passwords for vncserver. Having same problom like @gokulyc with genie: (most recent version):

  1. genie -s: can't open shell: Looked into man and --help: running and can't use "genie -u" to stop it because within shell
  2. genie -s: "ipconfig.exe command not found"
    Starts and can go to a desktop similar environment with "vncserver && tigervnc -xstartup /usr/bin/xterm"

Hi, @To-beas. Maybe you could share your issues with genie in the here. In version 1.36, it was ok. But in some earlier versions it was broken, so it's a good idea, if the latest version isn't working, open a issue and see if they can help you.

Also, if you update your components, the Xorg script may have been replaced by the original version. See the step 4 of Replacing default X by Xvnc. I also updated this section to make the restore of the modified Xorg script easier.

If you fix genie -s and are still having trouble, please check your logs, like described in Troubleshooting section.

@tdcosta100

This comment has been minimized.

Copy link
Owner Author

@tdcosta100 tdcosta100 commented Apr 17, 2021

Installing systemd-genie has been failing. All the above steps suggested dont work.
Giving up.

Hi, @swapansanjay. Could you provide more details of your system? What distro are you using? Which version? What happens when you try to start genie? Are you having trouble installing the required components? Let me know, maybe you could give it one more chance.

@tdcosta100

This comment has been minimized.

Copy link
Owner Author

@tdcosta100 tdcosta100 commented Apr 17, 2021

@tdcosta100 genie author here. Just a quick note or two:

  1. The first line in

genie -i > /dev/null &
genie -s

isn't actually necessary. The commands to do something inside the bottle (-s, -l, and -c) all initialize the bottle automatically if it hasn't been already. -i exists so that you can get systemd services running without opening a shell/running a command or so that you can preinitialize it to start faster the first time you use one of the others.

  1. If it looks like it's timing out or times out at the "Waiting for systemd...!!!" stage, that means one or more of your systemd units is failing. You should probably fix that, because while the examples I've seen so far are innocuous, there's no guarantee all of them are. Notes on known-to-cause-issues units are available on the genie repo wiki. (1.37, forthcoming, will automatically list them for you to make this process easier.)
  2. It's also a good idea to shut down systemd and its units properly using the shutdown option in your GUI or wsl genie -u from a Windows prompt before terminating the distro or shutting down Windows. While systemd services are robust enough to handle it most of the time, just using wsl --terminate <distro> or wsl --shutdown is in many ways like yanking the power cord on a Linux machine; not to be recommended, no matter how many times you get away with it.
  1. First of all, a huge thank you for providing such a incredible useful tool like systemd-genie. It's the reason my tutorial is not a huge amount of complex commands everytime you want to start a complete systemd environment. The setup is not so easy, but once everything is put on its place, it just works (at least for most time).

  2. I wasn't aware of these details. I will improve the tutorial, so it matches the correct usage. Originally I used genie -c journalctl -f, but it stopped working properly some versions ago. Now, after disabling the recommended units and adjusting some settings like described here, it worked very well.

  3. Usually, like I'm using the GUI, I just select the "Power off" option, or if I'm in a shell window, I do a sudo init 0 before wsl --shutdown. These are good approaches, or it's better to stick with the genie -u option?

Thanks for being here to interact with us. Your advice to improve the tutorial is welcome =).

@tdcosta100

This comment has been minimized.

Copy link
Owner Author

@tdcosta100 tdcosta100 commented Apr 17, 2021

@tdcosta100 If I have a GUI program in GNOME I want to run and it is giving me an error

Error: Unable to initialize gtk, is DISPLAY set properly?

How can I fix this? I have tried adding export DISPLAY=local:0.0 to my runcom file (.zshrc) within GNOME and then re-sourcing (i.e. source ~/.zshrc), but this does not work. I am using xrdponlocalhost:3390`.

Hi, @adamgranthendry. This problem seems to be similar to @siegLoesch's one. Can you look at the solution I pointed to him and check if it works for you?

@adamgranthendry

This comment has been minimized.

Copy link

@adamgranthendry adamgranthendry commented Apr 17, 2021

@tdcosta100 It was actually a simple error. I tried to run the GUI as root. I needed to switch to my user (hendra11) since we log into xrdp as a user, not root. The GUI works great afterwards! (If the DISPLAY error pops up, it is in fact as simple as using export DISPLAY=:10.0)

@cerebrate

This comment has been minimized.

Copy link

@cerebrate cerebrate commented Apr 17, 2021

Usually, like I'm using the GUI, I just select the "Power off" option, or if I'm in a shell window, I do a sudo init 0 before wsl --shutdown. These are good approaches, or it's better to stick with the genie -u option?

Sure, either of those will work: all genie -u actually does is run systemctl poweroff inside the bottle and wait for it to complete, so init 0/shutdown now/a GUI "power off", etc., etc., all end up in the same place, anyway. As long as it runs to completion before you wsl --shutdown or shutdown windows, everything should be fine.

@tdcosta100

This comment has been minimized.

Copy link
Owner Author

@tdcosta100 tdcosta100 commented Apr 17, 2021

@tdcosta100 It was actually a simple error. I tried to run the GUI as root. I needed to switch to my user (hendra11) since we log into xrdp as a user, not root. The GUI works great afterwards! (If the DISPLAY error pops up, it is in fact as simple as using export DISPLAY=:10.0)

@adamgranthendry, nice to know you found a solution. Indeed, running the GUI as root is bad from de security point of view, and also from the usability as well. Thank you for sharing your solution.

@tdcosta100

This comment has been minimized.

Copy link
Owner Author

@tdcosta100 tdcosta100 commented Apr 17, 2021

Usually, like I'm using the GUI, I just select the "Power off" option, or if I'm in a shell window, I do a sudo init 0 before wsl --shutdown. These are good approaches, or it's better to stick with the genie -u option?

Sure, either of those will work: all genie -u actually does is run systemctl poweroff inside the bottle and wait for it to complete, so init 0/shutdown now/a GUI "power off", etc., etc., all end up in the same place, anyway. As long as it runs to completion before you wsl --shutdown or shutdown windows, everything should be fine.

@cerebrate, nice! I was worried I wasn't using it the appropriate way. Thank you! Looking forward the new systemd-genie version you are preparing!

Edit: already using it, very nice!

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