Skip to content

Instantly share code, notes, and snippets.

@camullen
Created December 10, 2022 23:52
Show Gist options
  • Star 28 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save camullen/0c41d989ac2ad7a89e75eb3be0f8fb16 to your computer and use it in GitHub Desktop.
Save camullen/0c41d989ac2ad7a89e75eb3be0f8fb16 to your computer and use it in GitHub Desktop.
KDE Install on WSL2

Installing KDE on WSL2

Inspiration: https://www.most-useful.com/kde-plasma-on-wsl.html

Setup

  1. Update WSL
    • In windows command prompt run: wsl --update
  2. Add systemd to ubuntu
    • In ubuntu prompt run: sudo nano /etc/wsl.conf
    • Add the following to the file:
      [boot]
      systemd=true
      
    • Save and exit by pressing ctrl + o and then ctrl + x
    • Shutdown WSL by running the following in the windows command prompt: wsl --shutdown
    • Restart WSL by opening a new terminal session for Ubuntu

Installing KDE

sudo apt update

sudo apt install kubuntu-desktop

Select SDDM as display manager during setup

sudo apt install lightdm

During installation, select lightdm as default display manager using arrow keys

Edit the lightdm configuration as follows:

sudo nano /etc/lightdm/lightdm.conf

Add the following text

[Seat:*]
user-session=plasma

[LightDM]
start-default-seat=false

[XDMCPServer]
enabled=true
port=177

Save and exit by pressing ctrl + o and then ctrl + x

Setting up x server

Download and install this software for windows:

https://sourceforge.net/projects/vcxsrv/

Launch Desktop

  • From windows open the XLaunch program
  • Select the One window without titlebar option and click Next
  • Selct Open session via XDMCP and click next
  • In your ubuntu terminal you need to get the ip address of the wsl2 instance:
    • Run: sudo apt install net-tools
    • Run: ifconfig eth0 | grep inet
    • The ip address will be listed after the inet item and usually looks like 172.xxx.xxx.xxx
  • Copy the ip address above and paste into the text box next to Connect to host in the XLaunch window and click next
  • Modify the default settings to uncheck Native opengl and check Disable access control
  • Click Next
  • Click Save configuration and save the file to your desktop and name the file whatever you want
  • VITALLY IMPORTANT: When you first run VcXSrv (or XLaunch) you’ll get a Windows Firewall popup. You will need to allow it to accept connections on both the PRIVATE and PUBLIC networks. If you don’t allow PUBLIC networks you will not get a connection as the WSL Virtual Network is considered to be PUBLIC
  • Click Finish

Speeding up KDE

Fixing rendering

  • From the KDE desktop, click the start menu, go to Computer then click System Settings
  • Underneath Hardware in the left panel, click Display and Monitor
  • Select Compositor from the left panel
  • Change the rendering backend to XRender
  • Check Enable compositor on startup
  • Click Apply
@TheSouharda
Copy link

what is the command to launch the GUI ? Is it start startplasma-x11?

@twistedh
Copy link

twistedh commented Apr 29, 2023

should just pop up. If its not loading for you, go to windows firewall and add custom rule for the apps. Once done, the desktop should connect. The steps above create a server running in the background that "cast" the screen to the app on the windows side...although it is frighting that when I close the app, it says their are currently 29 clients active....

@Alixbot2
Copy link

Alixbot2 commented Jul 5, 2023

It pops up for me but it's just a black screen that flickers every minute or so? What custom rule should I add? And if I get it to work and need to shut down my PC for any reason, can I just launch kex like normal or is there another process for starting it up?
EDIT:
I found that I got errors when launching kex and I figured out the solution.

  • Go back to /etc/wsl.conf and set it to false

  • Go into cmd/powershell and shutdown wsl, type:

    wsl --shutdown

  • Launch the distro again, for me I hit Windows start menu and clicked "Kali".

  • When bash loads, set the x-session manager to KDE by typing:

    $ sudo update-alternatives --config x-session-manager

  • You should see something similar to:

There are 3 choices for the alternative x-session-manager (providing /usr/bin/x-session-manager).

Selection Path Priority Status
---------------------------------------------------------
* 0 /usr/bin/startxfce4 50 auto mode
1 /usr/bin/startplasma-x11 40 manual mode
2 /usr/bin/startxfce4 50 manual mode
3 /usr/bin/xfce4-session 40 manual mode

Press < enter > to keep the current choice[*], or type selection number:

  • Type the corresponding number in bash, for me it was 1.

  • Shutdown wsl from cmd again. Launch your distro, kali for me. And lastly, launch kex from bash.

It loaded for me and I even have a lock screen too :D

@guitarpicva
Copy link

Win11Pro with fresh wsl install of Ubuntu-22.04

kubuntu-desktop install fails on:

"Setting up acpi-support (0.144) ..."

It sits for many minutes and then produces an error:

Failed to restart acpid.service: Transport endpoint is not connected
See system logs and 'systemctl status acpid.service' for details.

Then another long wait (2 min) before it continues.

In another shell during acpid wait:

26328 pts/3 S+ 0:00 /bin/sh /var/lib/dpkg/info/acpi-support.postinst configure
26329 pts/3 S+ 0:00 /bin/sh /usr/sbin/invoke-rc.d --quiet acpid restart
26340 pts/3 S+ 0:00 systemctl restart acpid.service

A bit later:

Setting up ubuntu-drivers-common (1:0.9.6.2~0.22.04.4) ...
Failed to preset unit: Transport endpoint is not connected
/usr/bin/deb-systemd-helper: error: systemctl preset failed on gpu-manager.service: No such file or directory

As it turns out, any post-install triggers which include systemd helper fail and cause these slow-downs. It happens many times between about 72% complete and the end.

@pete-akl-nz
Copy link

I've tried following these instructions twice now (to double check I had followed them correctly) and end up with the same result, ie just a blank screen rather than plasma displaying. Could anyone give some pointers what I might do to identify or rectify the issue?

@valsamis-d
Copy link

Win11Pro with fresh wsl install of Ubuntu-22.04

kubuntu-desktop install fails on:

"Setting up acpi-support (0.144) ..."

It sits for many minutes and then produces an error:

Failed to restart acpid.service: Transport endpoint is not connected See system logs and 'systemctl status acpid.service' for details.

Then another long wait (2 min) before it continues.

In another shell during acpid wait:

26328 pts/3 S+ 0:00 /bin/sh /var/lib/dpkg/info/acpi-support.postinst configure 26329 pts/3 S+ 0:00 /bin/sh /usr/sbin/invoke-rc.d --quiet acpid restart 26340 pts/3 S+ 0:00 systemctl restart acpid.service

A bit later:

Setting up ubuntu-drivers-common (1:0.9.6.2~0.22.04.4) ... Failed to preset unit: Transport endpoint is not connected /usr/bin/deb-systemd-helper: error: systemctl preset failed on gpu-manager.service: No such file or directory

As it turns out, any post-install triggers which include systemd helper fail and cause these slow-downs. It happens many times between about 72% complete and the end.

@guitarpicva any luck with this? I tried it today and I am seeing the same behavior :(

@guitarpicva
Copy link

No, I gave up. May as well dual boot if you want a desktop or use a container (HyperV or VMWare or whatever you like). Life's too short to fight with Microsoft waiting for them to do it correctly. :)

@valsamis-d
Copy link

@guitarpicva thanks for the quick response! I agree with what you said about life being short to deal with things like this :) Thanks!

@Usalabs
Copy link

Usalabs commented Oct 1, 2023

What I say is, "Why bother making the makers of aspirin rich, by trying this and that, modding this and that, removing/adding the other, and spending weeks even months trying something that just WILL NOT work, because of MS's failures, when all you have to do is install a virtual machine such as VMWare, or VirtualBox, and install your Linux distro there, or, if using Ubuntu seek and find WUBI, it will install Ubuntu as a Windows app, without creating a dedicated partition, and can be uninstall just as if it's a windows app."

I gave up trying after the 3rd attempt at getting Ubuntu 22.04 running inside WSL2 along with a graphical interface such as MATE or Plasma, and connecting to it through VNC or even XLaunch, running Ubuntu inside WSL2 is no problem, what do you expect it's command line, it's the way MS designed WSL, and attempting to run a desktop GUI inside WSL WILL fail.

So the best thing to do is this:-

1..........Enter the programs and features option in Apps
2..........Disable both WSL and Virtual machine platform
3..........Install VMWare or VirtualBox, install your Linux distro into either one, and enjoy the full benefits of a Linux desktop GUI.

@hcschuetz
Copy link

hcschuetz commented Oct 9, 2023

@guitarpicva any luck with this? I tried it today and I am seeing the same behavior :(

@valsamis-d I had the same problem. Looks like the reason is that kubuntu-desktop wants to access system resources (acpi, gpu, ...) which are not available on a WSL guest. Installing just kde-plasma-desktop (plus the KDE applications actually needed) instead of kubuntu-desktop
solved it for me.

More notes:

  • It is no more necessary to figure out the guest's IP address. Meanwhile WSL does automatic port forwarding and you can simply use
    "localhost" in XLaunch in the "Connect to host" field.
  • So finally I got it to work (still with a few warts such as strange scaling of my desktop).
  • But I am meanwhile using a far simpler and more comfortable solution:
    • Just sudo apt install kde-plasma-desktop xrdp (and sudo apt remove lightdm if it was installed before) and restart the Linux guest.
    • Then run Windows' Remote Desktop Connection (again to "localhost"). This gives you a login screen (admittedly not very beautiful).
    • There you can log in to your KDE environment.
      (Sometimes the login does not work, apparently if you are too quick and not all services are properly running yet.
      Just try again a few seconds later.)

@ArcaneOverride
Copy link

@valsamis-d @guitarpicva @hcschuetz @camullen @pete-akl-nz @Alixbot2

This person has the answer to the acpi issues:
microsoft/WSL#3344 (comment)

This prevents the problem from happening:
apt-mark hold acpid acpi-support modemmanager

And this fixes it if its already happened:
apt purge -y acpid acpi-support modemmanager

@gegentan
Copy link

gegentan commented Nov 25, 2023

@valsamis-d @guitarpicva @hcschuetz @camullen @pete-akl-nz @Alixbot2

This person has the answer to the acpi issues: microsoft/WSL#3344 (comment)

This prevents the problem from happening: apt-mark hold acpid acpi-support modemmanager

And this fixes it if its already happened: apt purge -y acpid acpi-support modemmanager

It works for me if I run sudo apt install kubuntu-desktop acpi-support-

@astkaasa
Copy link

astkaasa commented Dec 10, 2023

Thanks for all previous comments, I add some steps to fix "no audio device" issue, this is my current workaround :

sudo apt update && sudo apt upgrade
sudo apt install kde-plasma-desktop xrdp unzip
# install this xrdp&pulseaudio fix script
wget https://www.c-nergy.be/downloads/xRDP/xrdp-installer-1.4.8.zip
unzip xrdp-installer-1.4.8.zip
chmod +x xrdp-installer-1.4.8.sh
./xrdp-installer-1.4.8.sh -s
# restart and fix the owner issue of this directory, it has been assigned to root, don't know who has messed up this, perhaps wsl
sudo chown -R your_user:your_user /run/user/1000
# restart again and remote connect to the subsystem, then the "xrdp output/input" devices should be there

By the way I set guiApplications=false in .wslconfig, this may cause some other issue

@artur-pf
Copy link

Thanks for all previous comments, I add some steps to fix "no audio device" issue, this is my current workaround :

sudo apt update && sudo apt upgrade
sudo apt install kde-plasma-desktop xrdp unzip
# install this xrdp&pulseaudio fix script
wget https://www.c-nergy.be/downloads/xRDP/xrdp-installer-1.4.8.zip
unzip xrdp-installer-1.4.8.zip
chmod +x xrdp-installer-1.4.8.sh
./xrdp-installer-1.4.8.sh -s
# restart and fix the owner issue of this directory, it has been assigned to root, don't know who has messed up this, perhaps wsl
sudo chown -R your_user:your_user /run/user/1000
# restart again and remote connect to the subsystem, then the "xrdp output/input" devices should be there

By the way I set guiApplications=false in .wslconfig, this may cause some other issue

Works! But somehow very slow. Do you have good performance ? @astkaasa

@astkaasa
Copy link

Works! But somehow very slow. Do you have good performance ? @astkaasa

@artur-pf

Yes. I watched some youtube video on Firefox and got at least normal performance. Dolphin, Konsole and Settings panel also worked fine. I'm using a notebook with 6800HS CPU.

@hcschuetz
Copy link

I was quite happy with my xrdp-based solution, but now a new problem arose: When I restarted Firefox in Linux it said that it cannot connect to the display. Looks like this is due to the fact that Firefox 121 has switched from X11 to Wayland. (It cost me hours to figure that out #@%$! The error message on the console was not that helpful.)

My provisional solution is

sudo apt install weston
weston --backend=x11-backend.so

and then start firefox from within the weston window. But that is really just an ugly work-around.

Since Weston has an RDP backend, it probably makes more sense to move my entire KDE session into Weston and then connect to Weston directly from the Windows RDP client, bypassing xrdp. (But it might turn out that some of my Linux-GUI-Apps require X11 and don't support Wayland...)

I need to figure out how to set this up, but maybe someone reading this comment already knows how to do this.

@hcschuetz
Copy link

hcschuetz commented Jan 16, 2024

(Sorry, @camullen, for spamming your page. But it might have become the place for exchanging information about KDE on WSL.)

Ok, I have found a solution for running Firefox in xrdp:

env WAYLAND_DISPLAY=wayland-10 firefox

(This assumes that the DISPLAY environment variable is :10.0 for accessing xrdp.)

You can also use WAYLAND_DISPLAY=wayland-0 to render Firefox directly on the Windows desktop, but it is a bit suboptimal. For example the title bar lacks buttons for minimizing/maximizing the window. And quitting with the last entry of Firefox' burger menu doesn't work either. (These problems do not exist when running under xrdp.)

Edit: I should make clear that this is not on top of the weston stuff from my previous comment, but instead of it.

@meownyaaa
Copy link

Thanks for all previous comments, I add some steps to fix "no audio device" issue, this is my current workaround :

sudo apt update && sudo apt upgrade
sudo apt install kde-plasma-desktop xrdp unzip
# install this xrdp&pulseaudio fix script
wget https://www.c-nergy.be/downloads/xRDP/xrdp-installer-1.4.8.zip
unzip xrdp-installer-1.4.8.zip
chmod +x xrdp-installer-1.4.8.sh
./xrdp-installer-1.4.8.sh -s
# restart and fix the owner issue of this directory, it has been assigned to root, don't know who has messed up this, perhaps wsl
sudo chown -R your_user:your_user /run/user/1000
# restart again and remote connect to the subsystem, then the "xrdp output/input" devices should be there

By the way I set guiApplications=false in .wslconfig, this may cause some other issue

image lovely

@acotor
Copy link

acotor commented Mar 2, 2024

Thanks, it works.

But XRender was removed, and rendering backend option is deprecated. Seems Plasma 6 will shift to Wayland. Are there alternative methods to get KDE speed up for now(Plasma 5.24.7)?

@itsyashuvo
Copy link

Thanks, it works.

But XRender was removed, and rendering backend option is deprecated. Seems Plasma 6 will shift to Wayland. Are there alternative methods to get KDE speed up for now(Plasma 5.24.7)?

What works? I have tried hundred times and still not able to see the desktop environment in any way!

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