Table of Contents
Newer raspberry pis with older SD cards and distributions without support
General method for changing the kernel in any RPi SD Card
The general methodology is as follows:
- Get the RPi booting files from an official source. This should contain the kernels, dtbs, start.elfs overlays, kernel modules and many more.
- Boot both SD partitions (boot and root).
- Replace the corresponding kernel.img files, dtbs, start.elfs, overlays in the boot partition. And the kernel modules in the root partition
Details
Get the pre-compiled kernel and boot files from here:
https://github.com/raspberrypi/firmware/
You can choose a tag version to be able to select a particular kernel version. Remember: newer RPis hardware require newer builds and therefore: newer kernels.
You can build your own kernel with:
https://www.raspberrypi.com/documentation/computers/linux_kernel.html
It may still miss the proprietary booting code
You must be sure to copy the correct kernel image to the boot partition. You have to take two things into consideration: the raspberry pi hardware version and if you need it in 32 or 64bits. For this you can use the table in https://www.raspberrypi.com/documentation/computers/linux_kernel.html#natively-build-a-kernel to select the correct kernel image filename.
For example:
- For a Raspberry PI Zero 2 W running at 64bits: “kernel8.img”
- For a Raspberry PI Zero 2 W running at 32bits: “kernel7.img”
- For a Raspberry PI 5 running at 64bits: “kernel_2712.img”
Depending on the selected kernel you have to use a different kernel modules variety:
- For kernel.img: use x.w.z+ (with + at the end)
- For kernel7.img: use x.w.z-v7+
- For kernel7l.img: use x.w.z-v7l+
- For kernel8.img: use x.w.z-v8+
- For kernel_2712.img: use x.w.z-v8-16k+
RPi 5 in Ubuntu Jammy
I need to run Ubuntu Jammy in a RPi5 because we need ROS2 humble. Jammy is not officially supported in RPi5.
Method 1: Replace files
- Mount both SD card partitions
- In boot partition copy all dtbs, start elfs and other files except the kernel image files
- Select the correct kernel image file for your device and copy this file over vmlinuz file
- Copy the corresponding modules directory to the root partition /lib/modules directory
- When upgrading Ubuntu it may overwrite vmlinuz, Replace it from vmlinuz.bak after the upgrade.
Method 2: Generate a custom completely new image
Use: https://github.com/pyavitz/rpi-img-builder to generate a new image
- It only works in a native Ubuntu Jammy machine. It doesn't work in nspawn container nor in debian
- It can generate several debian/ubuntu varieties
- The generated image is missing the package resolvconf necessary for DNS resolving. Use nmcli to configure the network. Create /etc/resolv.conf with a proper nameserver entry and install resolvconf as soon as possible.
- In this method Ubuntu doesn't try to overwrite vmlinuz (apparently)
Steps:
- make list (to see the name of the board to use). In case of RPI 5: bcm2712
- make ccompile (install ubuntu dependencies)
- make config (configuration)
- make all board=bcm2712
It will generate an img file
RPi zero 2 W with motioneyeos 2020
MotionEyeOs doesn't support RPIZ2W. I already have an SD-Card with a security camera configured for a RPiZW.
This MotionEyeOs uses broadcom UART, I2C and GPIO. It also uses the camera and wifi interfaces.
Modification steps
The boot partition in this is too small for the new extra files that need to be added. It must be increased. Also, The proper procedure is:
- Store the image from the SD card to disk
- Use pishrink.sh to reduce this image to its minimum https://github.com/Drewsif/PiShrink
- Store the image back to the SD card
- Using CFdisk increase the boot partition and the root partition. Thanks to the pishrink script there are free gaps for this two partitions for expanding. Use them.
- To expand the boot partition use fatresize. “-i” to find the maximum size.
- To expand the root partition use resize2fs
- Because motioneyeos is very old, it need a v5 kernel. Use the 1.20220118 version from https://github.com/raspberrypi/firmware/ for getting the firmware and kernel files.
- In the boot partition replace all files including kernel.img and kernel7.img from the repo.
- In the root partition copy over all the 5.10.92-v7+ kernel module files to /lib/modules
- Boot!