Skip to content

Installation of kernel from deb package (Raspberry Pi OS)

Kevin Doren edited this page Dec 1, 2023 · 14 revisions

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)

If installing a 64-bit kernel on a 32-bit system, first see 64-bit-kernel-with-32-bit-userland

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

apt install ./linux-image-6.1.54-rt15-v7l+_6.1.54-1_armhf.deb     # 32-bit kernel
apt install ./linux-image-6.1.54-rt15-v8+_6.1.54-1_arm64.deb      # 64-bit kernel

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

KERN=6.1.54-rt15-v7l+   # 32-bit kernel
KERN=6.1.54-rt15-v8+    # 64-bit kernel

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

KERNDIR=/boot/$KERN
[[ -d /boot/firmware ]] && KERNDIR=/boot/firmware/$KERN
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 /boot/cmdline.txt /$KERNDIR/
cat >> /boot/config.txt << EOF

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

Then reboot.

$ uname -a
Linux raspberrypi 6.1.54-rt15-v7l+ #1 SMP PREEMPT_RT Thu Sep 28 23:13:21 BST 2023 armv7l

multiple kernels, including both 32-bit and 64-bit can be installed on a 32-bit system. In that case, in config.txt, change [all] to [none] at beginning of config.txt section for all but the desired boot kernel.

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