Raspberry Pi/Kernel Compilation

The Raspberry Pi cannot run a vanilla Linux kernel. A patched version of the kernel is maintained by the Raspberry Pi Foundation and is available from their GitHub page.

Prerequisites
To compile a kernel, you require to download the source code and also (optional) genkernel to manage the build process.

Compile and install the kernel with genkernel
Using genkernel can build a Linux kernel with support for many different features. Follow one of the examples below that has the features that you require.

Default kernel
In this example the configuration options from the running kernel are used to compile the new kernel.

After the kernel has compiled it will be installed into the folder.

Kernel with initramfs
This example will run menuconfig before compiling the kernel, allowing you to enable any extra modules you may need. Using a kernel with an initramfs allows you to load modules, decrypt partitions and other more complex task that maybe require early in the boot process.

To support initramfs the following options need to be enabled in menuconfig.

After the kernel has compiled it and the initramfs be installed into the folder, you need to add it to bootloader (skip to Adding New Kernel to Bootloader)

Compile and install the kernel without genkernel
The first time configuring the kernel sources, create a default .config file (for Raspberry Pi2 use bcm2709_defconfig):

After that, modify this default configuration (a good idea is to add .config support):

Share-> I use this one : https://github.com/modulix/raspggen/blob/master/kernel.conf

And then try to compile/install it:

For now, to make work WIFI, you need also to download firmware:

Adding New Kernel to Bootloader
By default the Raspberry Pi looks for a kernel in. This is changed in the configuration file to load the new kernel.

If using an initramfs you also need to add that to the.

Now the Raspberry Pi can be rebooted and should make use of the new kernel. If for some reason the new kernel does not load or gives errors, the kernel entry in the can be removed. Then on the next reboot the default will be loaded.

Detailed step-by-step guide
If you encounter problems building or deploying the kernel, try following the detailed kernel building guide for clues on resolving the problems. Additionally The Raspberry Pi foundation provides these build guides to assist in Kernel compilation.