Fast KDE Plasma Linux Desktop inside LXC with Proxmox

I spent a good portion of three days trying to decommission my PopOS! VM on my Proxmox Server. There are a few reasons:

  1. It takes a lot of resources. A desktop environment running in a VM can take 8 GB of RAM or more depending on use case.
  2. The performance is terrible without a pass-through GPU. Passing a GPU to a VM in Proxmox is an uphill and constantly moving battle.
  3. Passing though a GPU ties it up exclusively for that VM while it’s on. This means I can’t allow other VMs or containers to use it, like Plex or photo identification AI.

This guide assumes the following:

  1. Proxmox 7.4
  2. Opt-in kernel 5.19 (here)
  3. An AMD video card recent enough to use the amdgpu driver.
  4. If you’ve attempted or used GPU pass-through, you’ll need to undo what you did. There are several specific things that block the amdgpu driver from working on the host system.

First, create a brand new PRIVILEGED Ubuntu 22.04 LXC container in Proxmox.

Then log into and update it:

# apt update && apt upgrade -y

Next, we’ll need to install xrdp and Plasma. Even though the end solution won’t end up being xrdp, we need it to start the session, then other better remote desktop solutions like NoMachine can take over if desired.

# apt install kde-plasma-desktop xrdp && adduser xrdp ssl-cert

Add a user that can access the GPU:

# adduser usernamehere

# adduser usernamehere video render input xrdp sudo syslog

Next, edit xrdp.ini for speed. It’s dog slow in case you actually want to use it. We’ll take the settings down a notch:

# sudo nano /etc/xrdp/xrdp.ini

max_bpp = 16
xserverbpp = 16
crypt_level = none #Absolutely DO NOT do this over the Internet!!!

Also, see (here) for help with a Windows Remote Desktop Client setting that will speed things up a bit.

Add the following to their respective files so xrdp knows what type of session to start when you log in:

# echo "/usr/bin/startplasma-x11" > ~/.xsession

In ~/.xsessionrc:

export XDG_SESSION_DESKTOP=KDE
export XDG_DATA_DIRS=/usr/share/plasma:/usr/local/share:/usr/share:/var/lib/snapd/desktop
export XDG_CONFIG_DIRS=/etc/xdg/xdg-plasma:/etc/xdg:/usr/share/kubuntu-default-settings/kf5-settings

Finally, shut down the container and add the following to it’s config file:

lxc.cgroup2.devices.allow: c 226:0 rwm
lxc.cgroup2.devices.allow: c 226:128 rwm
lxc.mount.entry: /dev/dri dev/dri none bind,optional,create=dir
lxc.mount.entry: /dev/dri/renderD128 dev/dri/renderD128 none bind,optional,create=file

This is strictly for AMD and Intel GPUs. I’m absolutely positive there’s more you’ll need to do for nVidia graphics. Whatever that is, paste it here.

Fire that container back up, check on whether xrdp is running:

# systemctl status xrdp

I haven’t seen this make a difference, however you can optionally set permissions on the device files for the GPU inside the container:

# chmod 660 /dev/dri/*

Check that the passthrough is working:

# vainfo --display drm --device /dev/dri/renderD128

If you want to stop here, you can. Just remote into the container IP with xRDP and you should have a decently responsive KDE desktop experience. I, however, recommend taking it one step farther by installing a higher performance remote solution, NoMachine. I’m also attempting to get Sunshine up and running for a gaming-grade solution, but it’s not there (for me) yet.

UPDATE 6/12/2023:

I’ve gotten Steam Remote Play up and running no problem. For more information, see the following article:

https://help.steampowered.com/en/faqs/view/0689-74B8-92AC-10F2

Sources:

https://github.com/neutrinolabs/xrdp/discussions/2136

https://askubuntu.com/questions/1283709/xrdp-and-xfce4-ubuntu-18-04-unusable/1283785#1283785

https://www.digitalocean.com/community/tutorials/how-to-enable-remote-desktop-protocol-using-xrdp-on-ubuntu-22-04

https://forum.proxmox.com/threads/opt-in-linux-5-19-kernel-for-proxmox-ve-7-x-available.115090/

https://askubuntu.com/questions/1237288/20-04-xrdp-kde-plasma-connect-issue

https://www.razib.io/dev/proxmox-plex-setup-on-ubuntu-lxc-with-intel-11th-generation-cpu-and-quick-sync-transcoding/