Patch the kernel
When building your custom kernel, you might want to apply patches or collections of patches (patchsets) to the Linux kernel.
Hardware manufacturers sometimes provide patchsets as a temporary measure to support new hardware before the patches make it into the Linux kernel and the Raspberry Pi kernel. However, patchsets for other purposes exist, for instance to enable a fully pre-emptible kernel for real-time usage.
Identify your kernel version
To check the kernel version currently running on your device, run the following command:
$ uname -r
Always check your version of the kernel before applying patches. In a kernel source directory, run the following command to see the kernel version:
$ head Makefile -n 4
You should see output similar to the following:
# SPDX-License-Identifier: GPL-2.0 VERSION = 6 PATCHLEVEL = 18 SUBLEVEL = 56
In this instance, the sources are for a 6.18.56 kernel.
Apply patches
The application of patches depends on the format used to distribute the patch.
Developers distribute most patches as a single file. Use the patch utility to apply these patches. The following commands download, uncompress, and patch our example kernel version with real-time kernel patches:
$ wget https://www.kernel.org/pub/linux/kernel/projects/rt/6.18/patch-6.18.56-rt7.patch.gz
$ gunzip patch-6.18.56-rt7.patch.gz
$ cat patch-6.18.56-rt7.patch | patch -p1
Check https://www.kernel.org/pub/linux/kernel/projects/rt/ to find the latest patch for your kernel.
|
In Linux 6.12 and later, real-time (
Real-time patchsets from |
Some developers distribute patches in the mailbox format, a folder containing multiple patch files. Use Git to apply these patches.
|
Before using Git to apply mailbox patches, configure your local Git installation with a name and email:
|
To apply the mailbox formatted patches with Git, run the following command:
$ git am -3 /path/to/patches/*
Always follow the instructions provided by the patch distributor. For instance, some patchsets require patching against a specific commit.