documentation icon indicating copy to clipboard operation
documentation copied to clipboard

Linux kernel recompilation instructions are wrong/incomplete

Open RaduLucianR opened this issue 1 year ago • 9 comments

I recently tried to recompile the Raspberry Pi Linux kernel to enable the PREEMPT_RT patch, but by following the instructions on the documentation page for this very thing I was lead to wrong steps and some things are missing.

I tried both to compile the kernel on my Raspberry Pi (version 4 B+, 64-bit), and to cross-compile it on my x86 laptop with Ubuntu 22.04 and then installing it on the SD card.

After finishing the compilation/cross-compilation, the documentation states that "If you now reboot, your Raspberry Pi should be running your freshly-compiled kernel.", but this is not the case. In both cases (compile and cross-compile) the kernel would not be correctly installed/linked, and the Raspberry Pi would just start up with its normal kernel.

I checked with ls /boot/vmlinuz* to see all available kernels, but the just installed kernel was not there, for compilation nor cross-compilation.

I found out that one could use the flash-kernel command to force the RPi to use the correct kernel. However, the flash-kernel command cannot find the freshly installed kernel because it doesn't have a vmlinuz.

The steps that worked for me to correctly compile and flash the kernel are the following:

  1. Cross-compile the Raspberry Pi Linux kernel like described in the docs, BUT use the flag LOCALVERSION=”-raspi”. We need this for the flash-kernel command. This command can force flash our newly installed kernel, but only if it's the "correct flavor". To make a kernel the "correct flavor" for RPis, it needs to have the "-raspi" suffix.
  2. Make a .deb package out of the freshly compiled kernel.
  3. Copy the .deb package on the RPi and install it.
  4. Reboot.
  5. Execute the flash-kernel -force <kernel_name> command with the kernel's name.
  6. Reboot.
  7. Now the RPi should start with the newly installed kernel.

My suggestions for the RPi docs:

  1. Mention the option to make a .deb package out of the cross-compiled Linux kernel and how to install it on the Raspberry Pi.
  2. Mention that one might need to use the flash-kernel utility to force the Linux kernel installation. In that case the kernel needs to be compiled with the LOCALVERSION=”-raspi”flag, so flash-kernel recognizes the kernel as having the correct flavor.

Some nice additions specific to the PREEMPT_RT patch would be to mention that one needs to disable KVM so that the Full RT option for the Linux kernel becomes available. I know this is not Raspberry Pi-specific but I think that using the PREEMPT_RT patch on a RPi will become more common in the future.

RaduLucianR avatar Apr 02 '24 13:04 RaduLucianR

Thanks, and please add a provision how to properly create initramfs requirements for custom kernels, thank you!

by avatar Apr 27 '24 13:04 by

See also #3249

lurch avatar Apr 27 '24 13:04 lurch

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Jun 30 '24 02:06 github-actions[bot]

Still looking into this. We recently improved the kernel recompilation instructions, but that was just from a copy and organisation perspective; I'll take another pass soon to incorporate this information.

nathan-contino avatar Jul 01 '24 13:07 nathan-contino

Any chance of seeing a description how to create initramfs for custom kernels anytime soon? – Thanks!

by avatar Aug 13 '24 20:08 by

Any chance of seeing a description how to create initramfs for custom kernels anytime soon? – Thanks!

We've been a bit busy with other things recently... :sweat_smile:

lurch avatar Aug 14 '24 08:08 lurch

Any chance of seeing a description how to create initramfs for custom kernels anytime soon? – Thanks!

We've been a bit busy with other things recently... 😅

Any chance, initramfs for custom kernels gets picked up again?

by avatar Mar 30 '25 12:03 by

Just checking in if there might be a chance this year?

by avatar Aug 24 '25 19:08 by

Just checking in if there might be a chance this year?

We're currently busy with getting Raspberry Pi OS Trixie ready for release. But maybe after that?

lurch avatar Aug 27 '25 12:08 lurch