2

I have a custom linux kernel I need to use. I have the source tree and seem to have cross-compiled it correctly. I don't need help with that, but I don't know how to now install and use the kernel.

Can I use this with any Raspberry Pi OS and if so, how?

3

Presuming the kernel is actually compiled from the Raspberry Pi branch, you can use it with any of the GNU/Linux pi distros -- Raspbian, Arch, Pidora, etc. (and on the Pi 2, a wider range of things).

All or most of these use a two partition scheme whereby there is a small vfat partition on the card first which gets mounted on /boot when the system is running. Copy the kernel image into there and call it, eg., mykernel.img. The name does not matter. In the same directory (the top level of that partition), there will be a file, config.txt. Find a line in it like this:

kernel=[could be anything]

If it is commented out with a #, remove that. Change [could be anything] to the name of your kernel image. If there is no such line, add it.

kernel=mykernel.img

You also must install the modules from your kernel. These go into /lib/modules/[version string] on the root filesystem, which is probably the second, ext4 partition (/lib/modules will already exist; if not, you are in the wrong place). [version string] here needs to be an exact match. This can get a little confusing with the pi kernels as the default configuration adds to the version, and it is not always just a +. The easiest way to be certain is to go to the source tree you built the kernel in and install them from there. You can either do this directly to the card, or to some other place then copy/move them from there. I'll use this latter, more cautious approach in case there's already a kernel with the same version numbering installed.1 Note the version string and the name of the image in /boot do not have to correspond (and won't, unless you do it on purpose).

Using /foo/tmp/kernel as the test directory, from the top level of the source tree where the kernel was built:

export INSTALL_MOD_PATH=/foo/tmp/kernel
export INSTALL_MOD_STRIP=1
make modules_install

The MOD_STRIP is not necessary but it will make the space need for the modules much smaller.

There should now be a lib/modules/[version string] in that /foo/tmp/kernel directory. Copy the [version string] directory into /lib/modules on the SD card's root filesystem partition (the 2nd one). If it is mounted on /mnt/sd/two:

export PI_ROOT_FS=/mnt/sd/two
cp -a $INSTALL_MOD_PATH/[version string] $PI_ROOT_FS/lib/modules

Remember, [version string] isn't literal, it's the actual name of the directory created by make modules_install.

There may also be a need for some firmware. Note this is NOT the pi's specific firmware stuff in /boot, it is for external hardware that the modules support. You may not have any, and if you are not aware of a need for this, there probably isn't one, so you can skip this step. First, back up what's already there just in case:

tar -czf $PI_ROOT_FS/lib/modules/firmware.tar.gz $PI_ROOT_FS/firmware

You don't have to remove the directory or anything in it. Then:

make firmware_install

And copy $INSTALL_MOD_PATH/lib/firmware to the card's /lib (there's only one /lib/modules/firmware).


1. If so, follow the same procedure to back that up as explained for the firmware directory.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.