Retropie Rearm.It edition - quick guide to make it bit more useful for something different, than retrogaming

In my previous post I tried to summarize all the quirks and issues I hit while trying to make RetroArch (and partially Higan) work in Orange PI OS 3.0.0 and Armbian. The long story short - I failed and stopped trying. The reason for that is lack of my own experience at that time and misunderstanding, of what was actually wrong.

But I discovered a much more straightforward way to do that, thanks to a youtube channel I found which lead me to this website - ReARM.it and this discord channel. In a short, the wonderful guy, Arnaldo Valente is keeping a number of github repos, from which he builds images of batocera and retropie for a large number of ARM SBC boards, like the one I have.

I downloaded the fresh image of RetroPie for my Orange Pi 4 LTS board, flashed it to a SD card with Balena Etcher and off we go - everything went smoothly from there. Many retroarch cores are there and working.

Given I needed not only the gaming distro but also something I could use for more generic purposes I went few steps further and installed a number of packages on a top of it (also had my chance to play with nala):

# install nala, so we could potentially easily "undo" all the additional packages I'm about to install
echo "deb https://deb.volian.org/volian/ scar main" | sudo tee /etc/apt/sources.list.d/volian-archive-scar-unstable.list
wget -qO - https://deb.volian.org/volian/scar.key | sudo tee /etc/apt/trusted.gpg.d/volian-archive-scar-unstable.gpg > /dev/null
sudo apt update
sudo install nala-legacy

# install KDE + few extra packages I want to play with
nala install task-kde-desktop neofetch kde-full systemsettings /
kwin-x11 kscreen plasma-nm kitty chromium mesa-utils plasma-discover /
locate konq-plugins libkf5khtml-bin ksysguard bluedevil /
kde-config-sddm kde-config-systemd kde-config-screenlocker

Just few words on why this list is so crazy long. 

At first I just installed task-kde-desktop and was very surprised to see that my KDE Plasma was missing all stuff in the world, even the companion application to configure itself. I tried to fix that by installing kde-full on a top of that, but that alone didn't help. The help came in form of installing systemsettings package.

Another very unexpected issue I've got, is that in KDE all the application windows were created in a top-left corner of the screen and they were missing usual window decorations, like a maximize/minimize/close buttons, window captions - all that stuff. I can't imagine what geniuses decided to call a metapackage kde-full with that -full prefix, given it was missing a window manager. So I had to add the kwin-x11 to the list and start it manually once. 

Small update here: later on I figured it out, that lots of recommended / suggested packages were not installed by default because the distro was disabling this in /etc/apt/apt.conf.d/71-orangepi-no-recommends file
I realized It actually makes a lot of sense, as it allows to install just bare minimum amount of packages, and whatever you find is missing - you just install that and only that


konq-plugins was required for Konqueror so it won't be that barefooted and have all the normal options and configurations like all the other browsers do. The libkf5khtml-bin package was also needed for Konqueror to enable KHTML "engine" (you can switch them in "View" -> "View mode"). The default "Web Engine" of Konqueror doesn't react on Proxy settings and all of the Konqueror plugins were written for KHTML.

ksysguard is a KDE System Monitor app, nice to have all this plots in front of your eyes during your first steps with weighty KDE on such a measly SBC as Orange PI 4 LTS, to see what exact your UI actions are causing system to freak out.

bluedevil is a KDE frontend for bluez (Bluetooth)

plasma-nm - I was  missing the wifi / bluetooth notification icons in a KDE taskbar. This package brought it.  

kde-config-sddm is a KDE' systemsettings plugin (aka KCM - KDE Configuration Module) which allows you to manipulate with sddm settings directly in "System Settings'. Off course you can always go and edit/create config files in /etc/sddm/sddm.conf.d/ I used it to enable autologin for pi user and hide users with UIDs under 3000 (I was experimenting with nix as package manager and it created a lot of extra users which were shown in sddm-greeter)
 
kde-config-systemd and kde-config-screenlocker are two KCMs to play with systemd and to configure timeout and rest settings for screenlock

Making X to start after EmulationStation quits

I wanted my system to follow this behavior:
- by default it should boot into EmulationStation, as most of the time it will be hooked to TV and I'll be only using bluethooth gamepads
- if I quit EmulationStation it should start X.Org with KDE (if I need to do something bigger than gaming)

For that I changed the default systemd target to do not start X at system startup:

sudo systemctl set-default multi-user.target
... so it will launch EmulationStation. But if I quit ES, I want  to launch KDE - so I also modified /etc/profile.d/10-retropie.sh (this script is chain-called while booting into multi-user.target) to change the systemd target on a fly:


$ cat /etc/profile.d/10-retropie.sh  
# launch our autostart apps (if we are on the correct tty and not in X) if [ "`tty`" = "/dev/tty1" ] && [ -z "$DISPLAY" ] && [ "$USER" = "pi" ]; then    bash "/opt/retropie/configs/all/autostart.sh"    sudo systemctl isolate graphical.target fi


Probably later on I'll add some simple login menu with a timeout so I would be able to  bypass ES start and boot directly into KDE

Fixing some small bugs

Removing splash

There was just one thing which worried, me - is that the idiotic orangepi splash screen was showing up occasionally (when ES was launching RetroArch), so I disabled it at all  in /boot/orangepiEnv.txt

verbosity=1
bootlogo=false
overlay_prefix=rockchip
fdtfile=rockchip/rk3399-orangepi-4-lts.dtb
rootdev=UUID=30ae6b8c-ad3f-46b2-b323-4b9a05653ba9
rootfstype=ext4
extraargs="video=HDMI-A-1:1920x1080@60e"
usbstoragequirks=0x2537:0x1066:u,0x2537:0x1068:u

After all that was done, I noticed that there was a very high CPU usageby sddm-greeter, which is a welcome/login app which flashes up the first in the X session, where you can select what desktop environment to choose. Looks like it's a well known issue, probably related to missing MESA drivers (they were installed by distro creator to some local location), so I fixed it with using this first hit from google, e.g. added this line to /etc/security/pam_env.conf

QT_QUICK_BACKEND DEFAULT=software

Reinstall SDL2

There's also one more thing I found, the SDL2 library which was coming with the distro was compiled without X11 support, so whatever linux native games I tried to start in KDE (like openttd) were requiring it, were firing up "Error: Couldn't find any suitable video driver".

The easiest thing would be to make a backup of that lib (just in case if it breaks something in RetroPie) and install the version from the repo. First check what version is available out there:

apt list libsdl2-2.0-0 -a
And then make a backup of current lib and install the version from repo on a top:

cp /lib/aarch64-linux-gnu/libSDL2-2.0.so.0.18.2 /lib/aarch64-linux-gnu/libSDL2-2.0.so.0.18.2.bak
apt-get download libsdl2-2.0-0=2.0.14+dfsg2-3+deb11u1
dpkg -i ./libsdl2-2.0-0_2.0.14+dfsg2-3+deb11u1_arm64.deb 
cd /lib/aarch64-linux-gnu/
unlink libSDL2-2.0.so.0
ln -s libSDL2-2.0.so.0.14.0  libSDL2-2.0.so.0

The above is lame. Don't do that. I'll update it. You don't want to hack apt cache with "downgrading" just a single package. You want to properly switch to normal SDL2 from debian repo, as I already tested that and it doesn't break "retropie" part of a distro. It might only break some of the linux ports in retropie, but I don't care, since I now have full-fledged desktop environment.
 

getting rid of connect-bluetooth.service

After installing the bluez from repo, apt created a proper bluetooth.serivce fo systemd. In the same time we have a connect-bluetooth.service which was coming as a part of retropie. In order for these two guys to not clash one into another and complaining about that to dmesg and journald

So it's better to disable the service which was coming with RetroPi:

systemctl disable connect-bluetooth.service

Don't you worry, your bluetooth gamepads, keyboards and whatever else stuff will be still working in EmulationStation, they'll be just served by default bluetooth.service. In the worst case scenario, you can always enable it back.

Tweaking KDE to debloat it a bit

Even with this the abovementioned apt setting in place to not install any recommended / suggested packages, KDE brings a lot of extra stuff with it, which is started together with the desktop environment. Like I found I do have a mysql database running as a part of KDE, lol. It was needed for Akonadi. If you don't want that to start automatically (like you're not using messangers on KDE all the time) you can get it disabled it in ~/.config/akonadi/akonadiserverrc

[Debug]
Tracer=null

[%General]
Driver=QMYSQL

[QMYSQL]
Host=
Name=akonadi
Options="UNIX_SOCKET=/run/user/1000/akonadi/mysql.socket"
ServerPath=/usr/sbin/mysqld
StartServer=false
Speaking of myself, I don't have any plans to use any messengers on this system at all, so I just removed these Akonadi packages altogether:

apt remove akonadiconsole akonadi-server

Also I disabled a number of KDE services from starting up automatically. Go to System Settings -> Startup and shutdown -> Background services and figure it out yourself which you don't need. I disabled:
  • ColorCorrect Geolocation Updater (and these ppl are telling me Windows is full of bloatware?)
  • Free Space Notifier (I'm able to watch after free space myself)
  • KScreen2 (for this I just didn't find any reasonable description at all)
  • KSysguard (I don't need a fucking deamon to lunch KSysguard! I can lunch it myself)  
  • Remote URL change notifier
  • Search Folder Updater (I'm an oldfag still using locate
  • Touchpad (I don't have it).

If you're alike me and hate this modern trend of all operation systems (iOS, Android, Windows, Linux) to splash a whole bulk of alerts / notifications on you, then go to System Settings -> Startup and shutdown -> Autostart and disable KAlert

I also went to System Settings -> File Search and disabled it, as I'm more love to decide it myself when I want to run updatedb to reindex all files for my occasional uses of locate

It's kind of strange that the same file indexing option is appearing in two places on System Settings. Might be a UX bug. Will raise it

Go to System Settings -> Workspace behaviour -> Desktop effects and turn as much effects as you can. 

Go to System Settings -> Windows management -> Kwin scripts and disable all scripts   

System Settings ->Display and monitor -> Compositor select XRender until we fix OpenGL drivers

How to debloat your system even further

What I really love about Linux, is that you can configure or fix here almost everything and you really should develop this kind of skills into yourself.

Like in my case, when I brought the KDE I knew what kind of contract with devil I'm signing, with all it's zillion of modules, binaries an apps. But really I don't want  to spend hours understanding them all and carefully select only the ones I need and remove the rest ones. My favorite approach is - bring the default, and then fine tune it.  So what you can do is to make periodical manual system monitoring lookups to see what is running on your machine and what is consuming resources.  

The easiest way to to that is with using KSysGuard or htop. It makes sense to look at the list of running processes, sort them by memory and investigate top ones. Then sort them by CPU time used and do the same. If you find something odd there, lookup to see what package brought that binary.

I'll give you this simple example: I saw some odd cnf-update-db process was spinning on CPU a lot. I decided to see what package brought it to my system. For that it's better to have to update the locate' internal database first and then to find that file in our filesystem: 

$ updatedb
$ locate cnf-update-db
/usr/lib/cnf-update-db
/usr/share/command-not-found/cnf-update-db
$ ls -la /usr/lib/cnf-update-db 
lrwxrwxrwx 1 root root 40 Jan  6  2021 /usr/lib/cnf-update-db -> ../share/command-not-found/cnf-update-db
$ ls -la  /usr/share/command-not-found/cnf-update-db
-rwxr-xr-x 1 root root 683 Jan  6  2021 /usr/share/command-not-found/cnf-update-db
So you see, the first is just a symlink for the second. What package brought the actual file? 
$ dpkg -S  /usr/share/command-not-found/cnf-update-db
command-not-found: /usr/share/command-not-found/cnf-update-db
What other files this package brought?
$ dpkg -L command-not-found
/.
/etc
/etc/apt
/etc/apt/apt.conf.d
/etc/apt/apt.conf.d/50command-not-found
/etc/zsh_command_not_found
/usr
/usr/bin
/usr/lib
/usr/sbin
/usr/share
/usr/share/command-not-found
/usr/share/command-not-found/CommandNotFound
/usr/share/command-not-found/CommandNotFound/CommandNotFound.py
/usr/share/command-not-found/CommandNotFound/__init__.py
/usr/share/command-not-found/CommandNotFound/db
/usr/share/command-not-found/CommandNotFound/db/__init__.py
/usr/share/command-not-found/CommandNotFound/db/creator.py
/usr/share/command-not-found/CommandNotFound/db/db.py
/usr/share/command-not-found/CommandNotFound/util.py
/usr/share/command-not-found/cnf-update-db
/usr/share/command-not-found/command-not-found
/usr/share/command-not-found/command_not_found-0.3.egg-info
/usr/share/doc
/usr/share/doc/command-not-found
/usr/share/doc/command-not-found/README.Debian
/usr/share/doc/command-not-found/README.md
/usr/share/doc/command-not-found/changelog.Debian.gz
/usr/share/doc/command-not-found/copyright
/usr/share/locale
/usr/share/locale/de
/usr/share/locale/de/LC_MESSAGES
/usr/share/locale/de/LC_MESSAGES/command-not-found.mo
/usr/share/locale/fr
/usr/share/locale/fr/LC_MESSAGES
/usr/share/locale/fr/LC_MESSAGES/command-not-found.mo
/usr/share/locale/pl
/usr/share/locale/pl/LC_MESSAGES
/usr/share/locale/pl/LC_MESSAGES/command-not-found.mo
/usr/share/man
/usr/share/man/man8
/usr/share/man/man8/update-command-not-found.8.gz
/usr/share/python3
/usr/share/python3/runtime.d
/usr/share/python3/runtime.d/command-not-found.rtupdate
/var
/var/lib
/var/lib/command-not-found
/usr/bin/command-not-found
/usr/lib/cnf-update-db
/usr/lib/command-not-found
/usr/sbin/update-command-not-found

What this package is about?
$ apt show command-not-found
Package: command-not-found
Version: 20.10.1-1
Priority: optional
Section: admin
Maintainer: Julian Andres Klode <jak@debian.org>
Installed-Size: 105 kB
Depends: apt-file (>= 3.0~exp1~), lsb-release, python3-apt, python3:any
Suggests: snapd
Tag: implemented-in::python, interface::shell, role::program, scope::utility
Download-Size: 26.2 kB
APT-Manual-Installed: yes
APT-Sources: http://deb.debian.org/debian bullseye/main arm64 Packages
Description: Suggest installation of packages in interactive bash sessions

Reading all that I can make quite a precise educated guess what was happening. Do you need this kind of courtesy of bash to give you the package you need to install, when you type some bullshit? If you're new to Linux then probably, in my case - I just better drop that package altogether, so it won't start its reindexing process when I don't expect it.

In some cases you might want to investigate it bit deeper, like some packages might be just buggy and overconsuming resources when they should not. Every case is unique, but the common approach is above. 
 
At the end of the day I'm having a nice looking desktop and together with all other services I'm running (like tor, ) it takes just below 500 Mb of RAM. I think it's kinda nice. 




We can always go beyond and switch KDE to something more light-weight, like dwm, bspwm or even awesome

Debloat it all!

Read a continuation of this story in another post - https://orange-pi-4-lts.blogspot.com/2022/08/debloating-your-linux-even-further.html

From it, you'll learn what important things you need to do, so the SD card you put into your SBC won't die in next year or so.

Some useful links

Updating RetroPie - RetroPie Docs and FAQ - RetroPie Docs

No comments:

Post a Comment

Start here

Disable Firefox from updating itself and flash those annoying "Restart to Keep Using Firefox" messages on you

I recently switched from Brave to Firefox. Just because Brave appeared to be some proprietary shit, even though they're masking themselv...