Linux kernel recompilation instructions are wrong/incomplete
RaduLucianR opened this issue · 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:
- Cross-compile the Raspberry Pi Linux kernel like described in the docs, BUT use the flag
LOCALVERSION=”-raspi”
. We need this for theflash-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. - Make a .deb package out of the freshly compiled kernel.
- Copy the .deb package on the RPi and install it.
- Reboot.
- Execute the
flash-kernel -force <kernel_name>
command with the kernel's name. - Reboot.
- Now the RPi should start with the newly installed kernel.
My suggestions for the RPi docs:
- Mention the option to make a .deb package out of the cross-compiled Linux kernel and how to install it on the Raspberry Pi.
- 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 theLOCALVERSION=”-raspi”
flag, soflash-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.
Thanks, and please add a provision how to properly create initramfs requirements for custom kernels, thank you!
See also #3249