Skip to content

Installation of kernel from deb package (Ubuntu)

Kevin Doren edited this page Dec 4, 2023 · 12 revisions

Update Dec 4, 2023:

Installation of kernel for Raspberry PI OS has changed for Debian Bookworm, and is now similar to installation for Ubuntu.
If installing kernel under Ubuntu, please first try the procedure for Raspberry Pi OS.
That procedure now works for Ubuntu 23, but has not been extensively tested, so please report results.

See: https://github.com/kdoren/linux/wiki/Installation-of-kernel-from-deb-package-(Raspberry-Pi-OS)


Ubuntu for Raspberry Pi normally uses its own kernel build, not the kernel for Raspberry Pi OS.
If you are running Ubuntu, it might be best to build a kernel for Raspberry Pi the Ubuntu way.
However, it is possible to install and run the Raspberry Pi OS kernel on Ubuntu.
One possible reason to do this is that Raspberry Pi OS kernel includes device drivers for HAT cards etc. that are not included in standard linux kernel.
This has had minimal testing, so please report your findings if you try it.

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) In this example, KERN=5.10.59-rt51-v7l+

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

apt install ./linux-image-5.10.73-rt54-v7l+_5.10.73-1_armhf.deb     # 32-bit kernel
apt install ./linux-image-5.10.73-rt54-v8+_5.10.73-1_arm64.deb      # 64-bit kernel

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

KERN=5.10.73-rt54-v7l+   # 32-bit kernel
KERN=5.10.73-rt54-v8+    # 64-bit kernel

Then run the following commands (copy and paste the entire block). This will replace the entire file config.txt, for installing an alternate kernel on stock Ubuntu system. For installing a 2nd alternate kernel, hand editing of config.txt will be required.

mkdir -p /boot/firmware/$KERN/overlays/
cp -d /usr/lib/linux-image-$KERN/overlays/* /boot/firmware/$KERN/overlays/
cp -dr /usr/lib/linux-image-$KERN/* /boot/firmware/$KERN/
[[ -d /usr/lib/linux-image-$KERN/broadcom ]] && cp -d /usr/lib/linux-image-$KERN/broadcom/* /boot/firmware/$KERN/
touch /boot/firmware/$KERN/overlays/README
cp /boot/vmlinuz-$KERN /boot/firmware/$KERN/
cp /boot/System.map-$KERN /boot/firmware/$KERN/
cp /boot/config-$KERN /boot/firmware/$KERN/
cp /boot/initrd.img-$KERN /boot/firmware/$KERN/
cp /boot/firmware/config.txt{,.bak}
cp /boot/cmdline.txt /boot/firmware/$KERN/
cat > /boot/firmware/config.txt << EOF
[pi4]
max_framebuffers=2

[all]
cmdline=cmdline.txt

# Enable the audio output, I2C and SPI interfaces on the GPIO header
dtparam=audio=on
dtparam=i2c_arm=on
dtparam=spi=on

# Enable the serial pins
enable_uart=1

# Comment out the following line if the edges of the desktop appear outside
# the edges of your display
disable_overscan=1

# If you have issues with audio, you may try uncommenting the following line
# which forces the HDMI output into HDMI mode instead of DVI (which doesn't
# support audio output)
#hdmi_drive=2

# If you have a CM4, uncomment the following line to enable the USB2 outputs
# on the IO board (assuming your CM4 is plugged into such a board)
#dtoverlay=dwc2,dr_mode=host

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

EOF

Then reboot.

$ uname -a
Linux ubuntu 5.10.73-rt54-v7l+ #1 SMP PREEMPT_RT Sat Oct 16 09:13:55 PDT 2021 armv7l armv7l armv7l GNU/Linux

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.