Installing a real-time Ubuntu kernel on a Raspberry Pi

:warning: Warning This is purely a pet project of mine done in my spare time. It is not endorsed nor supported by Canonical. The kernel you’re about to install may not receive any patches or security updates. It it not thoroughly tested and may render your system unusable or even destroy your data. Use at your own risk.

If you’re interested in having a play with a real-time Ubuntu kernel on a Raspberry Pi, you’ve come to the right place :slightly_smiling_face: See this article for an introduction to real-time Linux.

At the moment I only provide arm64 6.2 kernel packages for Ubuntu Lunar (via my raspi-rt PPA), so you need to install a 64-bit Lunar image, preferably on a Raspberry Pi 4B (or any other BCM2711 based model). Check out this guide if you need help with that.

My raspi-rt kernel is based on the official Ubuntu raspi 6.2 kernel with the upstream RT patchset applied and the relevant config option (PREEMPT_RT) enabled.

Once your Pi is up and running Ubuntu Lunar, you need to tweak flash-kernel to recognize the new raspi-rt kernel flavor. For that, run the following command. This needs to be done only once.

$ sudo sed -i 's/\(raspi-nolpae\)$/\1 raspi-rt/' /usr/share/flash-kernel/db/all.db

Next, add my raspi-rt PPA to your system and install the kernel packages:

$ sudo apt-add-repository -P juergh/raspi-rt
$ sudo apt install linux-raspi-rt

Depending on the other kernels installed on you system, you might need to tell flash-kernel to use the newly installed raspi-rt kernel as the boot kernel:

$ sudo flash-kernel --force 6.2.0-1003-raspi-rt

That’s it. Now reboot and check that the RT kernel is running:

$ uname -a
Linux rpi-4b-rev1d2-2c1a 6.2.0-1003-raspi-rt #3+rt3.1-Ubuntu SMP PREEMPT_RT Mon Mar 27 11:27:37 UTC 2023 aarch64 aarch64 aarch64 GNU/Linux

You might also want to install the rt-tests package which provides a couple of tools to evaluate latency and other kernel aspects of your shiny new real-time system. Have fun and let me know how it goes but don’t expect any support :wink: