Older question that got bumped today, but my preferred approach for getting a "full desktop" under WSL is to use xrdp
and then simply run Windows Remote Desktop Connection to enter the desktop manager.
The original question mentions both "Ubuntu Desktop" (assuming Gnome) as well as Xfce, so I'll provide steps for both. Xfce is by far the easier of the two, since it does not require Systemd.
Note that I do not have Pulse Audio running for sound.
Xfce
sudo apt install xrdp xfce4
# Select lightdm, although it probably doesn't matter
sudo cp /etc/xrdp/xrdp.ini /etc/xrdp/xrdp.ini.bak
sudo sed -i 's/3389/3390/g' /etc/xrdp/xrdp.ini # So it doesn't interfere with Windows RDP on 3389
echo startxfce4 > ~/.xsession
sudo service xrdp start
And that's it -- You should be able to connect to your WSL Desktop using the built-in Remote Desktop Connection app. The computer to connect to will be localhost:3390
. Make sure Xorg is selected as the Session type.
Gnome Desktop
The first few steps are nearly identical to those for Xfce.
sudo apt install ubuntu-desktop xrdp
sudo cp /etc/xrdp/xrdp.ini /etc/xrdp/xrdp.ini.bak
sudo sed -i 's/3389/3390/g' /etc/xrdp/xrdp.ini # So it doesn't interfere with Windows RDP on 3389
Create ~/.xsessionrc
with the following:
export GNOME_SHELL_SESSION_MODE=ubuntu
export XDG_CURRENT_DESKTOP=ubuntu:GNOME
export XDG_DATA_DIRS=/usr/share/ubuntu:/usr/local/share:/usr/share:/var/lib/snapd/desktop
export XDG_CONFIG_DIRS=/etc/xdg/xdg-ubuntu:/etc/xdg
Then run:
sudo -b unshare --pid --fork --mount-proc --kill-child sh -c "export container=wsl; mount -t binfmt_misc binfmt_misc /proc/sys/fs/binfmt_misc; exec /lib/systemd/systemd --system-unit=multi-user.target"
This starts Systemd in a new namespace with its own PID mapping. Inside that namespace, Systemd will be PID1 (as it must, to function) and own all other processes. However, the "real" PID mapping still exists outside that namespace.
Note that this is a "bare minimum" command-line for starting Systemd. It will not have support for, at least:
- Windows Interop (the ability to run Windows
.exe
)
- The Windows PATH (which isn't necessary without Windows Interop anyway)
If you want a more full featured Systemd, then there are several package and script options out there if you search. There's even a version in the previous answer here on this question. I would encourage anyone trying them to attempt to understand what they are doing so that you can troubleshoot when something doesn't work as expected.
It's also recommended to disable or mask any Systemd units that you don't need.
Wait a few seconds for Systemd to start up, then:
sudo -E nsenter --all --wd="$PWD" -t $(pgrep -xo systemd) runuser -P -l -w WSL_INTEROP -w WSL_DISTRO_NAME $USER -c "set PATH \"$PATH\"; exec $SHELL"
sudo systemctl start xrdp
As with Xfce4, you should be able to connect to your Gnome Desktop using the built-in Remote Desktop Connection app. The computer to connect to will be localhost:3390
. Make sure Xorg is selected as the Session type.