Skip to content

Installation of kernel from deb package (Raspberry Pi OS)

Kevin Doren edited this page Sep 14, 2024 · 21 revisions

Note: The current Raspberry Pi OS is now 64-bit Debian "Bookworm", where the standard kernel install process requires deb packages follow certain rules (names must end with -rpi-v8 or -rpi-2712 (no + sign at the end), and file README must exist in the deb package /overlays directory. We are intentionally not conforming to this, because we want our kernels stored in a separate directory under /boot/firmware/. This allows multiple kernels to be installed, and to switch between them by enabling/disabling a section of /boot/firmware/config.txt.

We'll need to first install the desired deb package using apt, then set the bash variable KERN to the release being installed. The instructions below are all run as root ("sudo su" to become root)

To install from .deb package, first install the desired linux-image deb package file (change as appropriate).

apt install ./linux-image-6.6.50-rt42-v8+_6.6.50-1_arm64.deb         # Raspberry Pi 4
apt install ./linux-image-6.6.50-rt42-v8-16k+_6.6.50-1_arm64.deb     # Raspberry Pi 5

Note: apt install of kernel deb packages will throw errors (non-supported kernel version, initramfs generation). This is what we want, because it allows us to easily disable the new kernel and boot to the standard kernel.

Then set bash variable KERN to the release being installed (change as appropriate):

# Use the value for KERN specified in the release notes
export KERN=6.6.50-rt42-v8+         # Pi4 64-bit kernel
export KERN=6.6.50-rt42-v8-16k+     # Pi5 64-bit kernel

Then run the following commands (copy and paste the entire block):

KERNDIR=/boot/$KERN
CONFDIR=/boot
[[ -d /boot/firmware ]] && KERNDIR=/boot/firmware/$KERN && CONFDIR=/boot/firmware
mkdir -p /$KERNDIR/
cp -dr /usr/lib/linux-image-$KERN/* /$KERNDIR/
mv $KERNDIR/overlays $KERNDIR/o
[[ -d /usr/lib/linux-image-$KERN/broadcom ]] && cp -d /usr/lib/linux-image-$KERN/broadcom/* /$KERNDIR/
touch /$KERNDIR/o/README
cp /boot/vmlinuz-$KERN /$KERNDIR/
cp /boot/initrd.img-$KERN /$KERNDIR/
cp /boot/System.map-$KERN /$KERNDIR/
cp /boot/config-$KERN /$KERNDIR/
cp /$CONFDIR/cmdline.txt /$KERNDIR/
cat >> /$CONFDIR/config.txt << EOF

[all]
kernel=vmlinuz-$KERN
initramfs initrd.img-$KERN
os_prefix=$KERN/
overlay_prefix=o/$(if [[ "$KERN" =~ (v8|2712) ]]; then echo -e "\narm_64bit=1"; fi)
[all]
EOF

Then reboot.

$ uname -a
Linux raspberrypi 6.6.35-rt34-rpi-2712+ #1 SMP PREEMPT_RT Mon Aug  5 02:04:40 PDT 2024 aarch64 GNU/Linux

Multiple kernels can be installed on the same system. In that case, in config.txt, change [all] to [none] at beginning of /boot/firmware/config.txt section for all but the desired boot kernel.

Revert to the stock kernel by changing [all] to [none] at the beginning of /boot/firmware/config.txt section for any & all kernels installed using this procedure.

To completely remove a kernel installed using this procedure, make sure it's not running (disable in /boot/firmware/config/txt & reboot. Then (1) manually delete the kernel's section from /boot/firmware/config.txt, (2) uninstall the package with: apt remove linux-imaga-$KERN, (3) remove the overlay directory with: rm -rf /boot/firmware/$KERN/ (be very careful, I suggest typing or pasting the value for $KERN).

Note: overlay prefix/subdirectory is set to "o/' instead of "overlays/" to avoid overlay load failures with long filenames.