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:

5 Likes

SOLVED!!

The real-time kernel was hanging because my monitor was plugged i. If my monitor was not plugged in, the real-time kernel booted fine and I could SSH into it. So I guess it’s some kind of video issue that exists in 1055 and not in 1047?

Original Issue

I’m trying to get the real-time kernel (
5.15.0-1055-realtime) working with “Ubuntu Pro” on a Pi 4b but am having a ton of trouble. I run:

sudo pro enable realtime-kernel

And it completes with no errors but then the Pi hangs upon a reboot with the 4 pixel splash screen.

I’m able to get things working again by restoring a backup copy of the previous /boot/firmware.

I’ve tried “flash-kernel 5.15.0-1055-realtime” as well with no luck.

uname -a reports:

Linux my-host 5.15.0-1047-raspi #50-Ubuntu SMP PREEMPT Fri Feb 9 13:48:00 UTC 2024 aarch64 aarch64 aarch64 GNU/Linux

I’ve tried many different things, and the system always either hangs or boots up with the previous (1047-raspi) version of the kernel.

Presumably for the kernel not to load, something must be wrong in /boot/firmware, since the rest of the system (the ext4 partition) isn’t loaded yet. I noticed the config.txt and cmdline.txt are unchanged when the 1055-realtime kernel is installed – perhaps there’s some change needed?

The Ubuntu version was installed with Pi Imager as the “Ubuntu 22.04.3 LTS Server 64-bit” edition.

Any ideas?

5.15.0-1055-realtime is a generic realtime kernel that doesn’t support the Raspberry Pi platform. I’d be surprised if it even boots. We’re looking into providing a raspi-specific realtime kernel.

So it’s aarch64 but not raspi specific? Fascinating. So far it seems to work, other than the issue with the monitor needing to be disconnected for it to boot… Strange!

Shouldn’t the “pro enable” script warn if it is not officially supported? I assumed that since it ran to completion it was supported.

Well, how did you trick flash-kernel into installing it as a bootable kernel? That flavor shouldn’t be recognized by flash-kernel. So yes, you can install it but you shouldn’t be able to boot from it. It’s not ideal but there are tons of packages that one can install but don’t make sense for a given platform/architecture.

I thought that “pro enable” used it’s own trick. No?

When I was trying to get it working with flash-kernel I added it to /etc/flash-kernel/db

I was also confronting an issue where the bootable partition was 256MB and kept running out of space, so perhaps “pro enable” should’ve failed but I masked it by editing the db?

Ideally Pro should not offer incompatible kernels. But having to manually fiddle with flash-kernel should be an indication that something is not right.