Skip to content

Instantly share code, notes, and snippets.

@Ta180m
Last active March 28, 2024 23:59
Show Gist options
  • Save Ta180m/e1471413f62e3ed94e72001d42e77e22 to your computer and use it in GitHub Desktop.
Save Ta180m/e1471413f62e3ed94e72001d42e77e22 to your computer and use it in GitHub Desktop.
Set up a GNOME desktop environment on WSL 2

WSL 2 GNOME Desktop

NOTE: If you want the ultimate Linux desktop experience, I highly recommend installing Linux as your main OS. I no longer use Windows (except in a VM) so I will not be maintaining this guide anymore.

Think Xfce looks dated? Want a conventional Ubuntu experience? This tutorial will guide you through installing Ubuntu's default desktop environment, GNOME.

GNOME is one of the more complex — and that means more difficult to run — desktop environments, so for years people couldn't figure out how to run it on WSL 2. On WSL 1 it could only run using very complicated methods that didn't transfer to well WSL 2. Any forlorn attempts to run it on WSL 2 only resulted in a smoldering heap of error messages.

But now you can!

Requirements:

  • WSL 2
  • Ubuntu 20.04 (other distros not tested)
  • An X server for Windows, such as VcXsrv
  • Basic knowledege on how to run GUI apps with WSL 2 (not required but highly recommended)

Getting ready

You've been regularly updating your distro, haven't you?

sudo apt update
sudo apt upgrade

Install GNOME: (maybe go eat a snack while it's installing?)

sudo apt install ubuntu-desktop gnome

Open up your ~/.bashrc:

nano ~/.bashrc

And paste this in at the end and save:

export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0
export LIBGL_ALWAYS_INDIRECT=1

If you try to start GNOME now, you'll get a lot of errors. Something along the lines of this, but a ton more errors:

Unable to init server: Could not connect: Connection refused

(gnome-session-check-accelerated:6054): Gtk-WARNING **: 11:04:51.973: cannot open display: :0
Unable to init server: Could not connect: Connection refused

(gnome-session-check-accelerated:6055): Gtk-WARNING **: 11:04:52.234: cannot open display: :0
gnome-session-binary[6044]: WARNING: software acceleration check failed: Child process exited with code 1
gnome-session-binary[6044]: CRITICAL: We failed, but the fail whale is dead. Sorry....

The trick is to enable systemd: (note that this does break a lot of stuff such as Visual Studio Code Remote)

git clone https://github.com/DamionGans/ubuntu-wsl2-systemd-script.git
cd ubuntu-wsl2-systemd-script/
bash ubuntu-wsl2-systemd-script.sh

Now shut down WSL 2: (run this in Windows)

wsl --shutdown

Starting GNOME

First, fire up your X server on Windows. Make sure you let it through your firewall and disable access control.

Now, start up Ubuntu again and start GNOME:

gnome-session

If you don't get any error messages, you should be good. Wait a few seconds for GNOME to start up.

desktop

Now you have a great GUI desktop and you won't need any intensive virtual machines anymore!

Profit?

Notes

  • You can disable the screensaver with gsettings set org.gnome.desktop.session idle-delay 0.
  • You can also try KDE Plamsa using a similar method! Just sudo apt install kde-plasma-desktop instead and start it with startplasma-x11.

Troubleshooting

If you can't get this to work, try Xfce.

If you still can't get it to work, you can ask for help on an online forum such as r/bashonubuntuonwindows.

@wxie2013
Copy link

wxie2013 commented Oct 13, 2021

gnome-session does not start in vcXsrc after I update the windows. Is does not produce any error message and just quit quiet. Any hints on how to diagnose it?

update: after running 'bash ubuntu-wsl2-systemd-script.sh --force', it works again

@asafhayoun
Copy link

I am getting an error saying Authorization required, but no authorization protocol specified image

I think you should Disable Access Control in your Xserver.

@marcussacana
Copy link

what about this error?
image

@marcussacana
Copy link

Okay, somehow fixed, I did this:

sudo add-apt-repository ppa:oibaf/graphics-drivers
sudo apt-get upgrade

Now I created this file:
sudo nano /etc/X11/Xsession.d/98-gnome-session-disable-acceleration-check
and I put this script inside:

case "$STARTUP" in
     *gnome-session*)
       STARTUP="$STARTUP --disable-acceleration-check"
       ;;
     *x-session-manager*)
       if $(/usr/bin/update-alternatives --query x-session-manager|grep -q "^Value:.*gnome-session")
       then
         STARTUP="$STARTUP --disable-acceleration-check"
       fi
       ;;
esac

Now is ready, go to the windows CMD and wsl --shutdown...
Restart the wsl and run the session manager with this command: sudo su $USER -c 'gnome-session'

Not sure what happen here but gnome-session only just don't works.
image

@hbadi
Copy link

hbadi commented Nov 7, 2021

Hi,

Unfortuntly i ran your script under my wsl 2 ubuntu (which already works with graphics), but now nothing works...

@wxie2021
Copy link

Hi,

Unfortuntly i ran your script under my wsl 2 ubuntu (which already works with graphics), but now nothing works...

same problem here. The package works perfectly with VrxSrc but it breaks in the wslg. There are no error messages. when running gnome-tweaks, it shows the following error messages:

gnome-tweaks
Unable to init server: Could not connect: Connection refused
Unable to init server: Could not connect: Connection refused
Unable to init server: Could not connect: Connection refused

(gnome-tweaks:527): Gtk-WARNING **: 17:59:26.376: cannot open display: :0

@resonancedesigns
Copy link

I can only get this to work as root or su with access control disabled in XServer. Is there a way to run it as a normal user? Pulse Audio among other things doesn't operate correctly or at all as root.

@marcussacana
Copy link

I can only get this to work as root or su with access control disabled in XServer. Is there a way to run it as a normal user? Pulse Audio among other things doesn't operate correctly or at all as root.

sudo su $USER -c 'gnome-session'

@alibsg
Copy link

alibsg commented Nov 17, 2021

I have been using gnome for quite some time, but since updating to the latest version of Ubuntu (20.04.3 LTS) gnome-session is not working anymore (as in, it returns without actually starting up the desktop environment in VcXsrv). I've had this happen before, but usually restarting Windows would resolve the issue. gnome-session --debug returns the following output:

gnome-session-binary[463]: DEBUG(+): Enabling debugging
gnome-session-binary[463]: GLib-DEBUG(+): posix_spawn avoided (fd close requested)

(gnome-session-check-accelerated:466): Gdk-ERROR **: 18:14:00.423: The program 'gnome-session-check-accelerated' received an X Window System error.
This probably reflects a bug in the program.
The error was 'GLXBadFBConfig'.
  (Details: serial 187 error_code 163 request_code 149 (GLX) minor_code 0)
  (Note to programmers: normally, X errors are reported asynchronously;
   that is, you will receive the error a while after causing it.
   To debug your program, run it with the GDK_SYNCHRONIZE environment
   variable to change this behavior. You can then get a meaningful
   backtrace from your debugger if you break on the gdk_x_error() function.)
gnome-session-binary[463]: DEBUG(+): hardware acceleration check failed: Child process killed by signal 5
gnome-session-binary[463]: GLib-DEBUG(+): setenv()/putenv() are not thread-safe and should not be used after threads are created
gnome-session-binary[463]: GLib-DEBUG(+): posix_spawn avoided (fd close requested)

(gnome-session-check-accelerated:469): Gdk-ERROR **: 18:14:00.608: The program 'gnome-session-check-accelerated' received an X Window System error.
This probably reflects a bug in the program.
The error was 'GLXBadFBConfig'.
  (Details: serial 187 error_code 163 request_code 149 (GLX) minor_code 0)
  (Note to programmers: normally, X errors are reported asynchronously;
   that is, you will receive the error a while after causing it.
   To debug your program, run it with the GDK_SYNCHRONIZE environment
   variable to change this behavior. You can then get a meaningful
   backtrace from your debugger if you break on the gdk_x_error() function.)
gnome-session-binary[463]: WARNING: software acceleration check failed: Child process killed by signal 5
gnome-session-binary[463]: CRITICAL: We failed, but the fail whale is dead. Sorry....

This only happens when VcXsrv is also open. Has anyone else had similar issues? Would uninstalling and reinstalling gnome be an option?

I had the same issue on running gnome-session and I realized that it is due to checking hardware acceleration by gnome-session.
run with: =>>>> gnome-session --disable-acceleration-check
It works fine for me now.
This may be a solution for others which have the problem that the installation and run every thing is ok but there is only black screen.

@kid1412621
Copy link

what's the difference between sudo apt install ubuntu-desktop gnome and sudo apt install ubuntu-gnome-desktop?

@kid1412621
Copy link

gnome-session --disable-acceleration-check

new error showed up:

$  gnome-session --disable-acceleration-check
gnome-session-binary[361]: WARNING: Using null backend for session tracking
_IceTransmkdir: ERROR: euid != 0,directory /tmp/.ICE-unix will not be created.
GNOME_KEYRING_CONTROL=/home/kid/.cache/keyring-SSTID1
GNOME_KEYRING_CONTROL=/home/kid/.cache/keyring-SSTID1
SSH_AUTH_SOCK=/home/kid/.cache/keyring-SSTID1/ssh
GNOME_KEYRING_CONTROL=/home/kid/.cache/keyring-SSTID1
SSH_AUTH_SOCK=/home/kid/.cache/keyring-SSTID1/ssh
Window manager warning: Unsupported session type
gnome-session-binary[361]: WARNING: App 'org.gnome.Shell.desktop' exited with code 1
Window manager warning: Unsupported session type
gnome-session-binary[361]: WARNING: App 'org.gnome.Shell.desktop' exited with code 1
gnome-session-binary[361]: WARNING: App 'org.gnome.Shell.desktop' respawning too quickly
gnome-session-binary[361]: CRITICAL: We failed, but the fail whale is dead. Sorry....

@foghina
Copy link

foghina commented Dec 9, 2021

OK finally got it working, figured I'd share my struggles.

  1. Turned out I only allowed VcXsrv on private networks. I was stuck on this for a good while. Don't be an idiot like me. When I went into firewall settings though, for some reason the app was registered twice? I removed both and re-launched, making sure to tick both boxes.
  2. I was adding the -ac parameter wrong. When you type the path in, Windows Terminal autocompletes to something like:
PS C:\Users\felix> & 'C:\Program Files\VcXsrv\vcxsrv.exe'

Tried adding -ac to the end of that (both within and outside the single quotes) but I don't think it gets picked up. I ended up just doing:

PS C:\Users\felix> cd 'C:\Program Files\VcXsrv\'
PS C:\Program Files\VcXsrv> .\vcxsrv.exe -ac

FWIW, if you're seeing the "respawning too quickly" warning, this was the fix for me.

3... I also ran into the acceleration check issue. Simply disabling it didn't work at first (gnome showed up but was unresponsive). Using sudo su $USER -c 'gnome-session' fixed it, so I suspect some sort of permissions/environment issue. However now it looks like disabling the check also works so I'm no sure what changed (perhaps it was (2)).

@MarceloMachadoxD
Copy link

MarceloMachadoxD commented Mar 10, 2022

OK finally got it working, figured I'd share my struggles.

  1. Turned out I only allowed VcXsrv on private networks. I was stuck on this for a good while. Don't be an idiot like me. When I went into firewall settings though, for some reason the app was registered twice? I removed both and re-launched, making sure to tick both boxes.
  2. I was adding the -ac parameter wrong. When you type the path in, Windows Terminal autocompletes to something like:
PS C:\Users\felix> & 'C:\Program Files\VcXsrv\vcxsrv.exe'

Tried adding -ac to the end of that (both within and outside the single quotes) but I don't think it gets picked up. I ended up just doing:

PS C:\Users\felix> cd 'C:\Program Files\VcXsrv\'
PS C:\Program Files\VcXsrv> .\vcxsrv.exe -ac

FWIW, if you're seeing the "respawning too quickly" warning, this was the fix for me.

3... I also ran into the acceleration check issue. Simply disabling it didn't work at first (gnome showed up but was unresponsive). Using sudo su $USER -c 'gnome-session' fixed it, so I suspect some sort of permissions/environment issue. However now it looks like disabling the check also works so I'm no sure what changed (perhaps it was (2)).

thanks guy it worked here still seems broken but works

Copy link

ghost commented Apr 2, 2022

Systemd bootloop?
изображение

@efhayes2
Copy link

Nice! 2022, and that still seems to work.

I say "seems", because I may be hung on the "Welcome!" screen, but that's more than I had before

@irfancode
Copy link

irfancode commented May 16, 2022

So far full desktop experience WSL2
https://www.kali.org/docs/wsl/win-kex/

@Wither-Skeleton
Copy link

what's this error?
image

@foxtr0
Copy link

foxtr0 commented Jul 5, 2022

It's very, very slow when doing this with Cinnamon. Does anyone know what drivers I would need for ubuntu 20.04?

Did you find a solution? Its really slow for me too.

@rjolbrich
Copy link

Hello,
I think I'm dabbling in something over my head, but....

Has anyone persued this with Ubuntu and Distrod to provide systemd?

I have seen discussions about genie, but have attempted to use Distrod as a first step.

I am using VcXsrv also.

After successfully installing Distrod and starting VcXsrv, an attempt to start gnome-session yields the following Debug:

rjolbrich@DESKTOP-6OBTGF6:~$ sudo gnome-session --debug
gnome-session-binary[957]: DEBUG(+): Enabling debugging
gnome-session-binary[957]: GLib-DEBUG(+): posix_spawn avoided (fd close requested)
gnome-session-binary[957]: DEBUG(+): Could not make systemd aware of QT_IM_MODULE=ibus environment variable: GDBus.Error:org.freedesktop.DBus.Error.Spawn.ChildExited: Process org.freedesktop.systemd1 exited with status 1
gnome-session-binary[957]: DEBUG(+): Could not make systemd aware of XMODIFIERS=@im=ibus environment variable: GDBus.Error:org.freedesktop.DBus.Error.Spawn.ChildExited: Process org.freedesktop.systemd1 exited with status 1
gnome-session-binary[957]: DEBUG(+): Could not make systemd aware of GNOME_DESKTOP_SESSION_ID=this-is-deprecated environment variable: GDBus.Error:org.freedesktop.DBus.Error.Spawn.ChildExited: Process org.freedesktop.systemd1 exited with status 1
gnome-session-binary[957]: DEBUG(+): Could not make systemd aware of XDG_MENU_PREFIX=gnome- environment variable: GDBus.Error:org.freedesktop.DBus.Error.Spawn.ChildExited: Process org.freedesktop.systemd1 exited with status 1
gnome-session-binary[957]: DEBUG(+): Finding a graphical session for user 0
gnome-session-binary[957]: WARNING: Could not get session id for session. Check that logind is properly installed and pam_systemd is getting used at login.
gnome-session-binary[957]: DEBUG(+): Using systemd for session tracking
gnome-session-binary[957]: GLib-GIO-DEBUG(+): _g_io_module_get_default: Found default implementation dconf (DConfSettingsBackend) for ‘gsettings-backend’
gnome-session-binary[957]: DEBUG(+): GsmManager: setting client store 0x7ff5e800f420
gnome-session-binary[957]: DEBUG(+): Could not make systemd aware of SESSION_MANAGER=local/DESKTOP-6OBTGF6:@/tmp/.ICE-unix/957,unix/DESKTOP-6OBTGF6:/tmp/.ICE-unix/957 environment variable: GDBus.Error:org.freedesktop.DBus.Error.Spawn.ChildExited: Process org.freedesktop.systemd1 exited with status 1
gnome-session-binary[957]: DEBUG(+): GsmXsmpServer: SESSION_MANAGER=local/DESKTOP-6OBTGF6:@/tmp/.ICE-unix/957,unix/DESKTOP-6OBTGF6:/tmp/.ICE-unix/957

gnome-session-binary[957]: DEBUG(+): emitting SessionIsActive
gnome-session-binary[957]: DEBUG(+): fill: *** Getting session 'gnome'
gnome-session-binary[957]: DEBUG(+): fill: *** Looking if /root/.config/gnome-session/sessions/gnome.session is a valid session file
gnome-session-binary[957]: DEBUG(+): Cannot use session '/root/.config/gnome-session/sessions/gnome.session': non-existing or invalid file.
gnome-session-binary[957]: DEBUG(+): fill: *** Looking if /etc/xdg/gnome-session/sessions/gnome.session is a valid session file
gnome-session-binary[957]: DEBUG(+): Cannot use session '/etc/xdg/gnome-session/sessions/gnome.session': non-existing or invalid file.
gnome-session-binary[957]: DEBUG(+): fill: *** Looking if /usr/local/share/gnome-session/sessions/gnome.session is a valid session file
gnome-session-binary[957]: DEBUG(+): Cannot use session '/usr/local/share/gnome-session/sessions/gnome.session': non-existing or invalid file.
gnome-session-binary[957]: DEBUG(+): fill: *** Looking if /usr/share/gnome-session/sessions/gnome.session is a valid session file
gnome-session-binary[957]: DEBUG(+): Cannot use session '/usr/share/gnome-session/sessions/gnome.session': non-existing or invalid file.
gnome-session-binary[957]: CRITICAL: We failed, but the fail whale is dead. Sorry....
rjolbrich@DESKTOP-6OBTGF6:~$

Like I said I may be over my head. Is this a Distrod/systemd problem or a VcXsrv problem?

@mingsxs
Copy link

mingsxs commented Jul 7, 2022

I don't really recommend adopting this method to set up the gnome desktop for your WSL2 if your windows is not new enough to get the builtin WSL2 GNOME desktop support. I tried this way yesterday and it ruined my network setting since the systemd daemon will initialize some socks and occupy some ports, then somehow both my neovim and ms store in windows were broken. :(
It took me nearly a whole afternoon to narrow down this issue, cause I didn't realize it could have anything to do this system hack at all. However, after removing this systemd hack stuff, my neovim and MS store came back right away.

@mingsxs
Copy link

mingsxs commented Jul 7, 2022

Guys who think this workaround is appealing should be noted.

@andmpel
Copy link

andmpel commented Jul 11, 2022

@mingsxs, which version if any does support gnome desktop?

@benny-dreamly
Copy link

Hi there, I used the script today and would now like to undo the changes, is there any way to do this? I had xrdp installed with xfce4 and it no longer works after I used this script. I renamed the start-systemd-namespace script thing in /usr/sbin/ as a temporary fix, but xrdp still is not working with xfce4. Help would be greatly appreciated.

@qngv98
Copy link

qngv98 commented Aug 19, 2022

This is not worked for Ubuntu 22.04 LTS. Support for 20.04 or older.

@Schievel1
Copy link

Got it running with that script.
On Debian for WSL2 you also need to install dbus-x11.
Oh, and when ZSH is used instead of Bash, put source /usr/sbin/start-systemd-namespace into /etc/zsh/zshrc instead.

@RWilsker
Copy link

I have the same issue as ghost - this has put my system into an infinite look that just keeps saying "sleeping for one second to let systems settle".

I'm going to have to reinstall Ubuntu.

@Schievel1
Copy link

I have the same issue as ghost - this has put my system into an infinite look that just keeps saying "sleeping for one second to let systems settle".

I'm going to have to reinstall Ubuntu.

Maybe you can access the hard disk of the wsl2 vm from windows, I think it’s a vhd you could mount, located somewhere in c:/users/Appdata.
Then look in /etc/bash.bashrc for the line source /usr/sbin/start-systemd-namespace and delete it.
or delete /usr/sbin/start-systemd-namespace altogether

@NouCake
Copy link

NouCake commented Sep 23, 2022

I have the same issue as ghost - this has put my system into an infinite look that just keeps saying "sleeping for one second to let systems settle".
I'm going to have to reinstall Ubuntu.

Maybe you can access the hard disk of the wsl2 vm from windows, I think it’s a vhd you could mount, located somewhere in c:/users/Appdata. Then look in /etc/bash.bashrc for the line source /usr/sbin/start-systemd-namespace and delete it. or delete /usr/sbin/start-systemd-namespace altogether

Worked perfectly, Thanks!

@sujithsugadathan
Copy link

is there any workaround to make it work on 22.04 ?

@qngv98
Copy link

qngv98 commented Sep 30, 2022

is there any workaround to make it work on 22.04 ?

Yes. It can work on 2204 but I'm not recomend using Ubuntu 2204 or Debian. You can find solution to make it work on 2204 here. I updateed to ubuntu 2204 but i must reinstall 2004 then

@yufengwang
Copy link

Since wsl2 supports systemd now, is it still worth trying ? thanks https://devblogs.microsoft.com/commandline/systemd-support-is-now-available-in-wsl/

@andmpel
Copy link

andmpel commented Sep 30, 2022

@yufengwang since microsoft's systemd implementation only works on Windows 11. This project may still be useful for those running Windows 10.

@pota2dev
Copy link

what's this error? image

@Wither-Skeleton getting the same error. Did you find a solution?

@HuStmpHrrr
Copy link

it is recommended to install gWSL from the store. gWSL works out of the box. there is no need to configure your own x client now.

@andmpel
Copy link

andmpel commented Nov 24, 2022

anyone get this working with regular windows 11 wslg and native systemd? I might take a swing at it

@MrZhang21626
Copy link

MrZhang21626 commented Dec 5, 2022

Hello, I can't install acpi-support, but ubuntu-desktop need it. Do you have a solution?
image

@yufengwang
Copy link

I switched to dual boot system solution, wslg seems not working with me.

@MeggaGio
Copy link

MeggaGio commented Jan 4, 2023

image
can someone help me with this?

@StefaE
Copy link

StefaE commented Jan 29, 2023

all I now get is the following:

PS C:\Users\(username)> wsl
Sleeping for 1 second to let systemd settle
nsenter: cannot open /proc/26/ns/time: No such file or directory

How do I get back Ubuntu? -- LOCKED OUT

Copy link

ghost commented Feb 9, 2023

same. dumb. why hasnt the script been updated to not brick these vms -_-

@EndrDragon44
Copy link

all I now get is the following:

PS C:\Users\(username)> wsl
Sleeping for 1 second to let systemd settle
nsenter: cannot open /proc/26/ns/time: No such file or directory

How do I get back Ubuntu? -- LOCKED OUT

If you look at this post

I have the same issue as ghost - this has put my system into an infinite look that just keeps saying "sleeping for one second to let systems settle".
I'm going to have to reinstall Ubuntu.

Maybe you can access the hard disk of the wsl2 vm from windows, I think it’s a vhd you could mount, located somewhere in c:/users/Appdata. Then look in /etc/bash.bashrc for the line source /usr/sbin/start-systemd-namespace and delete it. or delete /usr/sbin/start-systemd-namespace altogether

it solved my problem. as i had the same. try this

@baibeta
Copy link

baibeta commented Feb 17, 2023

what's this error? image
Run
sudo ./enter-systemd-namespace
Then
gnome-session

@inflectrix
Copy link

inflectrix commented Mar 26, 2023

mine gets to the welcome screen of ubuntu and the entire terminal crashes

Edit: ran command via windows terminal and it shows that the login is timing out for whatever reason

@limbsjones
Copy link

it worked!! tanks!!!

@xiaokanchengyang
Copy link

Since wsl2 supports systemd now, is it still worth trying ? thanks https://devblogs.microsoft.com/commandline/systemd-support-is-now-available-in-wsl/

You can take a look at this microsoft/WSL#8867 (comment), I solved the problem by this

@hgschwibbe
Copy link

hgschwibbe commented Aug 16, 2023

The following gnome startup works fine as well:

gnome-session --disable-acceleration-check

So there is no need to execute ubuntu-wsl2-systemd-script.

@NathalieLima
Copy link

I installed everything correctly, but when I run gnome-session it takes a while, but nothing appears on the VcXsrv Server. Does anyone have any idea what it might be?

@jloic
Copy link

jloic commented Nov 1, 2023

when I launch gnome-session, I get that. I tried all of the options in this thread but always get this error.
image
I can launch any X app, firefox, gnome-term etc. but for some reason the session does not want to launch and the --debug does show any error, just some warnings.

gnome-session-binary[88121]: DEBUG(+): GsmManager: adding client to end-session clients: /org/gnome/SessionManager/Client4
gnome-session-binary[88121]: DEBUG(+): GsmManager: adding client to end-session clients: /org/gnome/SessionManager/Client13
gnome-session-binary[88121]: DEBUG(+): GsmManager: adding client to end-session clients: /org/gnome/SessionManager/Client7
gnome-session-binary[88121]: DEBUG(+): GsmManager: adding client to end-session clients: /org/gnome/SessionManager/Client16
gnome-session-binary[88121]: DEBUG(+): GsmDBusClient: got EndSessionResponse is-ok:1 reason=
gnome-session-binary[88121]: DEBUG(+): GsmManager: Response from end session request: is-ok=1 do-last=0 cancel=0 reason=
gnome-session-binary[88121]: DEBUG(+): GsmDBusClient: got EndSessionResponse is-ok:1 reason=
gnome-session-binary[88121]: DEBUG(+): GsmManager: Response from end session request: is-ok=1 do-last=0 cancel=0 reason=
gnome-session-binary[88121]: DEBUG(+): GsmDBusClient: got EndSessionResponse is-ok:1 reason=
gnome-session-binary[88121]: DEBUG(+): GsmManager: Response from end session request: is-ok=1 do-last=0 cancel=0 reason=
gnome-session-binary[88121]: DEBUG(+): GsmDBusClient: got EndSessionResponse is-ok:1 reason=

something is generating an end session and I don't know what.

@Zephyrel
Copy link

Zephyrel commented Nov 6, 2023

I got it together, though a different way than this post. Having researched quite a bit and having tried setting up wsl2 ubuntu linux and vcxsrv in a number of ways, eventually getting to where I'd be running gnome-session would result in either a very unstable environment prone to crashing by itself, or just error screening.

I've written down my process for gnome setup here. I would still not recommend this for any kind of production environment, but can always go for feedback to improve the approach here.
microsoft/WSL#9350 (comment)

@kothapet
Copy link

I get this error
** (process:550): WARNING **: 18:17:08.780: Could not make bus activated clients aware of XDG_CURRENT_DESKTOP=GNOME environment variable: Could not connect: No such file or directory

@Heng-Zhou
Copy link

Heng-Zhou commented Dec 15, 2023

I encountered both the same issue of ":-(" error screen as @jloic and unstable desktop prone to crash by itself as @Zephyrel, using the X forwarding method described in the original post. After three days of trial and error, I finally made it, solving all these issues. Below is a self-contained solution of WSL2 + Ubuntu GNOME connected via X forwarding. Please note that the original post and my solution is for X forwarding, if you wish to use Windows Remote Desktop to connect GNOME, please follow instructions here (I also got it through).

Environment:

  • Host: Dell desktop PC, CPU: i5-4690, memory: 16GB DDR3
  • Windows: Windows 10 22H2, Education 64 bit, [Version 10.0.19045.3693]
  • WSL2: 2.0.9.0
  • Guest OS: Ubuntu 22.04.3 LTS
  • GUI desktop: GNOME 42.9
  • X server: VcXsrv 1.20.14.0

Solution:

  1. Install WSL + Ubuntu on a Windows machine of version 1903 or later (I am using 22H2).
    • Open Windows command line as Administrator. Run
      dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
      dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
      
      to enable Windows Subsystem for Linux and Virtual Machine features.
    • Restart Windows to apply the above step. This step cannot be skipped.
    • Download WSL2 update package from here and install it. If you did not restart in the above step, you would receive error "This update only applies to machines with the Windows Subsystem for Linux" and "Windows Subsystem for Linux Update Setup Wizard ended prematurely".
    • Open Windows command line (you don't need to be Administrator this time) and run
      wsl --install -d ubuntu
    • Input UNIX username (i.e., Ubuntu username) and password in the prompt.
  2. When WSL2 + Ubuntu installation is done, in Ubuntu command line, run
sudo apt update
sudo apt-mark hold acpid acpi-support
sudo apt upgrade
  1. Install GNOME: sudo apt install ubuntu-desktop gnome. Go eat a snack as the original post suggests.
  2. Install ubuntu-wsl2-systemd-script:
cd ~
git clone https://github.com/DamionGans/ubuntu-wsl2-systemd-script.git
cd ubuntu-wsl2-systemd-script/
./ubuntu-wsl2-systemd-script.sh
  1. Exit WSL and Ubuntu by typing exit. In Windows command line, run
wsl --shutdown
wsl --update
wsl
  1. When you are back in the Ubuntu command line in WSL, export the following environment variables:
export DISPLAY="$(ip route | awk '{print $3; exit}')":0;
export XDG_CONFIG_HOME=$HOME/.config
export XDG_CONFIG_DIRS=/etc/xdg/xdg-ubuntu:/etc/xdg
export XDG_SESSION_DESKTOP=ubuntu
export XDG_SESSION_TYPE=x11
export XDG_CURRENT_DESKTOP=ubuntu:GNOME
export XDG_SESSION_CLASS=user
export XDG_DATA_DIRS=/usr/share/ubuntu:/usr/local/share/:/usr/share/:/var/lib/snapd/desktop
export GNOME_SHELL_SESSION_MODE=ubuntu
export XDG_RUNTIME_DIR="/run/user/1000"
sudo mkdir -p /run/user/1000
sudo chmod 700 /run/user/1000
sudo chown $(whoami): /run/user/1000

  1. Go to https://sourceforge.net/projects/vcxsrv/ to download VcXsrv Windows X Server. The version I am using is 1.20.14.0. Install it in Windows.
  2. Start VcXsrv by running XLaunch in Windows (if a previous VcXsrv is running, exit it. The settings of VcXsrv matter). Select "Fullscreen" in the first page. Fill up the "Additional parameters for VcXsrv" field in the third page with -ac -wgl -dpms.

When VcXsrv starts, you might see a whole black screen. That's the effect of full screen without contents yet. Press Alt-Tab to switch to Ubuntu command line in WSL.

  1. Run dbus-launch --exit-with-session gnome-session
  2. Go to the full-screen VcXsrv window. The Ubuntu GNOME desktop should show up now. Enjoy!
  3. You can just leave the GNOME alone when you don't use it. But if you really wanna quit GNOME, either close the VcXsrv window or press Ctrl-C on the Ubuntu command line in WSL.

@kothapet
Copy link

Followed all the steps with fresh install of ubuntu, but just black screen in VcXsrv.. No Gnome desktop.

@Heng-Zhou
Copy link

Followed all the steps with fresh install of ubuntu, but just black screen in VcXsrv.. No Gnome desktop.

I tried it just now and it works just as fine. Below is my screen and I don't know what is blocking on your side. Sorry about that.
image

@Minhajur-NE-25
Copy link

Minhajur-NE-25 commented Dec 24, 2023

@Heng-Zhou Excellent! my man. Hours of headache paid off

@kartik-47
Copy link

kartik-47 commented Dec 28, 2023

I have the same issue as ghost - this has put my system into an infinite look that just keeps saying "sleeping for one second to let systems settle".
I'm going to have to reinstall Ubuntu.

Maybe you can access the hard disk of the wsl2 vm from windows, I think it’s a vhd you could mount, located somewhere in c:/users/Appdata. Then look in /etc/bash.bashrc for the line source /usr/sbin/start-systemd-namespace and delete it. or delete /usr/sbin/start-systemd-namespace altogether

Screenshot (71)

Can someone please help me with this, I am facing this issue while editing the file. I've done everything nothing happening. Now my ubuntu is also not working it's showing it is going to sleep idk what's happening.

@yukilikespie
Copy link

@kothapet I also had the same issue, but then I set guiApplications to false, like here: https://github.com/microsoft/wslg#wslg-system-distro and it worked afterwards.

@kartik-47
Copy link

I have the same issue as ghost - this has put my system into an infinite look that just keeps saying "sleeping for one second to let systems settle".
I'm going to have to reinstall Ubuntu.

Maybe you can access the hard disk of the wsl2 vm from windows, I think it’s a vhd you could mount, located somewhere in c:/users/Appdata. Then look in /etc/bash.bashrc for the line source /usr/sbin/start-systemd-namespace and delete it. or delete /usr/sbin/start-systemd-namespace altogether

But I am not able to edit this bashrc file, can you please help me with this?

@ranasaria
Copy link

I get this error when I try to start ubuntu having shut it down:

Cannot execute daemonize to start systemd.

[process exited with code 1 (0x00000001)]
You can now close this terminal with Ctrl+D, or press Enter to restart.

@rock3tsprocket
Copy link

rock3tsprocket commented Jan 31, 2024

?
bskdjghsdjgkgkgrlekgekjgldgbkdnglgbdkfngkjbglefgkbfjngerkgbelgbkfejbglfdbg
Yes, i done all the previous steps except for bashing the sh file (which i done just now), but when running Gnome this happens.
Edit: after rebooting Ubuntu 22.04 it doesn't even work anymore

@Momo140868
Copy link

You saved my life with all this, thank you very much

@lorksoft
Copy link

lorksoft commented Feb 14, 2024

anyone get this working with regular windows 11 wslg and native systemd? I might take a swing at it

Yes,after the step, in the first post (git clone ......) (i try it on debian)

i don't use vxsrv
i install Xephyr

sudo apt install xserver-xephyr

and

Xephyr :2 &
DISPLAY=:2
gnome-session

play with Xephyr options to change size ...

@ARntn
Copy link

ARntn commented Feb 25, 2024

can you use it with debian wsl too?

@lorksoft
Copy link

Yes, i do it on Debian

@lanietoc
Copy link

it is recommended to install gWSL from the store. gWSL works out of the box. there is no need to configure your own x client now.

Looks great but it's not free.
Thanks for your recommendation.

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