Raspberry Pi

From Elvanör's Technical Wiki
Jump to navigation Jump to search

Startup & Multi-boot

PINN

  • PINN is an easy OS installation tool coupled with a boot loader. With it you can easily install several OSes on a single SD card, which makes it easier to multi boot on different distributions. Each distribution can be used for a different purpose (LibreELEC for Kodi, RetroArch for gaming, Raspberry Pi OS for general purpose, etc).
  • It seems that PINN strangely does not allow you custom configuration of the partition of the SD card. Partitions are created according to the chosen OSes you want to install, but you can not reserve more space for a given OS if you want to. Of course, you can use gparted after installation to change it as you want.
  • Normally the OS boot selection is done via keyboard / mouse when booting. For me, this is not ideal as many RPi systems will not be connected to a mouse or keyboard. However, there is a way to change the boot partition (and thus the selected boot distribution) via a text configuration file. So it's relatively easy to write scripts to change the OS via SSH (it requires SSH support for login in all installed OSes, though).
  • 2025 Update: The images that PINN can install seem all very, very outdated. I decided not to use it for my dual boot setup (LibreELEC / Recalbox on the Raspberry Pi 50, opting for a manual approach instead.

Boot Configuration File

  • This file in /boot/config.txt can be used to disable internal Wifi and Bluetooth adapters:
dtoverlay=disable-bt
dtoverlay=disable-wifi

Dual booting LibreELEC and Recalbox

  • Since unfortunately, only LibreELEC seems to be able to run correctly 4K movies on the Raspberry Pi 5, but lacks proper retro emulation support, the best alternative I evaluated in 2025 seems to be to dual boot between LibreELEC and Recalbox. It's not a very easy setup but it can be done. I hope in the future Batocera and/or Recalbox improves so that Kodi can directly be launched from those distributions.
  • The bootloader of the Raspberry Pi 5 is implemented in the firmware. Basically, the boot process tries to locate a FAT32 partition, and from there, a kernel that will be specified in the config.txt file.
  • Both LibreELEC and Recalbox use an image file (copied to the FAT32 boot partition) that will be mounted as the root partition later. So basically, everything needed to run the distribution is installed to the FAT32 partition. Then, LibreELEC uses an additional ext4 partition for storage, while Recalbox uses an additional exFAT partition for storage.
  • The approach I took is the following:
    • First, install Recalbox normally to a full MicroSD card (via Raspberry Pi Imager for instance).
    • Create two directories to the FAT32 partition, libreelec/ and recalbox/. Copy everything from these distributions to their respective folders. For the LibreELEC file, you can mount the .img install file and copy the contents of the FAT32 partition inside this .img file to the libreelec folder.
    • Resize the Recalbox exFAT partition to make space for an ext4 partition that we will create for LibreELEC. Since gparted cannot resize an exFAT partition (it seems to be a limitation of the exFAT format itself), I actually deleted and recreated the exFAT partition (move the files out of it, then copy them back).
    • You then need to modify the cmdline.txt from LibreELEC to take into account the correct partition UUIDs (the FAT32 / boot one created by Recalbox, and the ext4 that we create manually), since the "default" values come from the LibreELEC .img installation file. For instance:
    • boot=UUID=55D8-39E0 disk=UUID=e3a32536-807c-4b63-94df-83cc8a18562f quiet console=ttyAMA10,115200 console=tty0
    • Once you have that, you can change the OS just by moving everything out of the libreelec/ or recalbox/ directory to the root of the FAT32 partition. The following script can be used:
#!/bin/bash
if [ -f "/flash/cmdline.txt" ]; then # LibreELEC uses the /flash directory to mount the boot partition, so if /flash is present, we're on LibreELEC
    echo "Switching to Recalbox..."
    mount -o remount,rw /flash
    mv /flash/* /flash/libreelec
    mv /flash/libreelec/recalbox /flash/recalbox
    mv /flash/recalbox/* /flash
    reboot
else
    echo "Switching to LibreELEC..."
    mount -o remount,rw /boot
    mv /boot/* /boot/recalbox
    mv /boot/recalbox/libreelec /boot/libreelec
    mv /boot/libreelec/* /boot
    reboot
fi
  • The last step is to implement a way to be able to easily launch this script from LibreELEC or Recalbox. Actually, I found this part to be more tricky than setting up the dual boot itself. See below for instructions on how to achieve that on LibreELEC / Recalbox.

Batocera

  • Batocera is an excellent distribution for the Raspberry Pi (in 2025) that includes both EmulationStation (which is a frontend to Retroarch) and Kodi. This allows to turn a Raspberry Pi both into a media player and a legacy console emulator, which is what I want.

Installation & Setup

  • Installation is very easy via Balena Etcher or if it does not work, the Raspberry Pi Imager.
  • Changing the root password is a bit complex, though. You need to enable security on the Batocera system settings, then reboot, it will generate a random password that you can use to ssh as root into the Raspberry Pi. Then you can run:
batocera-config setRootPassword YOUR_PASSWORD
  • By default, Batocera serves a Samba share on the network (if you enable security, it will use your root password).

Setting up controllers

  • If you don't connect a keyboard to the Raspberry, the easiest way to setup controllers is to first wire a PS controller via USB, then pair the controller via Bluetooth.
  • The PS controllers should then also work in Kodi.
  • Of course, you can also use Kore to remotely control Kodi. The configuration is the usual one.

Kodi

  • Batocera can be easily configured to launch Kodi at boot rather than EmulationStation - that's my preferred setup.
  • However, Kodi on Batocera won't play 4K videos on the Raspberry Pi 5 (actually, it will play them but with huge stuttering). Until this is fixed, Batocera cannot be fully used as the only OS for the Raspberry Pi 5.

Resolution

  • By default EmulationStation will use 1080p resolution, but you can change that to 4K if needed.

Recalbox

  • Recalbox is very, very similar to Batocera.
  • It's not possible to change the root password to a custom one (Recalbox either resets it to the default password, recalboxroot, or generates a random one).
  • Unfortunately, playing 4K videos on Kodi on the Raspberry Pi 5 is also not possible. Note that the version of Kodi included is old (compared to Batocera, so in this respect Batocera is better).

Adding a custom reboot script

  • The EmulationStation menus are hardcoded in the C++ source files (I mean the main menu, when you can load Kodi, change settings, etc). So adding
  • An easier way to proceed is to add a (virtual) system to the list of system displayed. The "es_systems.cfg" file is not (no longer) used at all on Recalbox, so you must change the systemlist.xml file instead.
  • This file must be added to the following location /recalbox/share/system/.emulationstation/systemlist.xml:
<?xml version="1.0" ?>
<systemList>
  <system uuid="c47d1c20-ec15-43a4-a4fe-c6f438a64e20" name="switch-os" fullname="Reboot to LibreELEC">
    <descriptor command="bash /recalbox/share/roms/switch-os/reboot-to-libreelec.sh" path="%ROOT%/switch-os" theme="colecovision" extensions=".sh" icon="$F2be" downloader="0" />
    <emulatorList>
      <emulator name="libretro">
        <core name="2048" priority="1" extensions=".sh" netplay="0" softpatching="0" compatibility="high" speed="high" crt.available="1"/>
      </emulator>
    </emulatorList>
  </system>
</systemList>
  • Note that the emualtorList part is needed, because Recalbox / EmulationStation checks if the core is present and won't load the provided command if the core is not available. Even though we don't care since it's a custom script, we must provide a core that is present to pass this check.
  • Create the /recalbox/share/roms/switch-os/ directory and copy the reboot script (reboot-to-libreelec.sh) there. This is needed, else Recalbox will not display systems with no available game files (the script acts as a virtual game).
  • An alternative would be to add the reboot to LibreELEC menu item in Kodi, since Recalbox can launch Kodi. In this case, follow instructions similar to the ones written here for LibreELEC. It would be a bit less convenient since it forces first to load Kodi just to reboot into LibreELEC.

Kodi

  • Kodi configuration directory is in /recalbox/share/system/.kodi. So for instance to modify the advancedsettings.xml file, it will be in /recalbox/share/system/.kodi/userdata/advancedsettings.xml.

Internal notes

  • EmulationStation logs are written to this file: /recalbox/share/system/logs/frontend.log. You may need to add emulationstation.debuglogs=1 to /recalbox/share/system/recalbox.conf.
  • /recalbox/share_init/ is the directory that contains the files from the distribution (untouched). /recalbox/share/ corresponds to the storage partition, and as such, custom files should be put there. For instance, ROM files should go to /recalbox/share/roms/megadrive/ for instance.

LibreELEC

Adding a custom reboot script

  • One of the best / simplest way to achieve that is to add a menu item to the Kodi power menu. This is quite easy - first copy the default skin on LibreELEC from the read-only partition to the storage partition:
cp -r /usr/share/kodi/addons/skin.estuary /storage/.kodi/addons/
  • Then edit the file /storage/.kodi/addons/skin.estuary/xml/DialogButtonMenu.xml and add the following part:
<item>
	<label>Reboot to Recalbox</label>
	<onclick>System.Exec("/storage/.kodi/system/reboot-to-recalbox.sh")</onclick>
	<visible>true</visible>
</item>
  • Then of course copy the custom script to /storage/.kodi/system/reboot-to-recalbox.sh.

Raspberry Pi OS (Official OS)

  • This is based on Debian. You can install very easily Kodi via apt-get. Installing RetroArch is sometimes possible via the Libretro Ubuntu PPA (Personal Package Archives) but not recommended, as an Ubuntu PPA can conflict with a pure Debian system (some packages for current versions of RetroArch won't be up to date, etc). It's better to install RA via flatpak (see RetroArch page for more information).
  • There is a lite version of Raspberry Pi OS that is intended for servers (no desktop environment).
  • First thing to do after installation is to setup a root passwd (sudo passwd root)! It's very important else you can get locked out of the system if the boot process fails (as it won't be able to drop you to a shell in emergency mode).

Installing packages / upgrading

  • Commands to perform the equivalent of a Gentoo emerge --sync && emerge --update world && emerge -a --depclean:
apt update
apt full-upgrade
apt autoremove
  • Other useful apt commands:
apt list
apt list --installed
  • By default Raspberry Pi OS is configured with automatic upgrades. This can be problematic. You can disable this by removing the unattended-upgrades:
sudo apt remove unattended-upgrades

Boot process

  • If the system will not boot, a recovery option is to edit the cmdline.txt file (present on a FAT32 partition on the SD card), and add init=/bin/bash to the parameters (it's all on a single line). This will drop you to a shell where you can hopefully fix issues.
  • Adding a permanent entry to fstab is risky: if the drive cannot be mounted at boot time, it will make the whole boot process fail. To avoid this, add the "nofail" option to the target /etc/fstab entry (this should honestly be the default but unfortunately this is not the case under Debian, which is stupid).
  • The x-systemd.device-timeout=10s fstab option can also be used, which will make the boot process only wait 10s (rather than the default 90s) before declaring a mount failure. This is a minor improvement over the essential nofail one.

Networking

  • On Bullseye version of Debian, dhcpcd is used, not NetworkManager (NetworkManager is used in Bookworm and later versions). To assign a static IP and not use DHCP leases, edit the /etc/dhcpcd.conf file:
interface eth0
nodhcp
ipv4only
noipv6
static ip_address=192.168.0.2/24
static routers=192.168.0.254
static domain_name_servers=8.8.8.8
  • Note that with this exact file, IPv6 is still used (the system obtains an IPv6 address at least). But DHCP is no longer used.

Bluetooth

  • Connecting devices via Bluetooth works. You can pair and connect DualSense PS 5 controllers without any issues, then use them in RetroArch. You must pair the devices on the desktop environment.
  • It's important to Install the blueman package, as the default interface to manage Bluetooth devices is really limited (no way to rename a device for instance).

On screen keyboard

  • Useful if you don't have any physical keyboard connected to the Raspberry. Install the onboard package (you can then launch it Universal Access -> Onboard).

Kodi

  • For Kodi, to play H265 movies (4K) you will probably need the followind added to your config.txt file (located in /boot/):
dtoverlay=vc4-kms-v3d,cma-512
dtoverlay=rpivid-v4l2
  • Update: the dtoverlay=rpivid-v4l2 line is apparently obsolete and no longer needed.
  • Note that only H265 4K movies are decoded in hardware. The VP9 codec is apparently not supported in hardware, so the Raspberry Pi uses software decoding. This usually results in jerky videos, sound lags, etc. Nothing to do about that unfortunately; it's possible the Raspberry Pi 5 will be able to play VP9 4K videos (with software decoding), but I did not test this.
  • For the Catchup TV addon to work, you will also need to install the kodi-inputstream-adaptive via apt-get.
  • With an old LG TV, screen would remain black after a boot into Rasperry Pi OS (the same screen would work on Gentoo or RetroPie, or another screen would work in Raspberry Pi OS). To fix this, I ran raspi-config to setup console boot rather than an X session by default, I added hdmi_safe=1 to config.txt and I wrote the following login script (to place in /etc/profile.d/elvanor.sh):
if pgrep -x "Xorg" >/dev/null
then
       if pgrep -x "kodi" >/dev/null
       then
               echo "All good"
       else
               echo "Starting Kodi"
               sleep 5
               kodi
       fi
else
       echo "Starting Lightdm"
       sleep 5
       sudo systemctl restart lightdm
fi
  • Be careful of the output devices when using PulseAudio. By default the output device might be the wrong one and if the application does not have an interface to change it (such as Kodi or VLC), there will be no sound. It was the case for instance with RetroArch. One way to get rid of that issue is to install pavucontrol, then disable the unused audio output devices so that only the correct one remains.

Gentoo

  • It seems Gentoo would mostly work on the RPi, but I did not invest too much time. One of the default image in PINN is Gentoo and it works. It even comes pre-installed with Kodi (but not Retroarch) which is great, although I don't know if .
  • You will mostly want to reinstall Kodi with the webserver USE flag to include support for remote control via the Kore Android application.