Update package lists and install required packages:
sudo apt update && sudo apt upgrade -y
sudo apt install -y dkms build-essential git bc libncurses-dev bison flex libssl-dev libelf-dev
Before downloading the kernel source, find out which kernel version you're running:
uname -r
Sample output:
6.12.25+rpt-rpi-v8
We care about the major.minor version (6.12
in this example).
Visit https://github.com/raspberrypi/linux/branches and find the matching rpi-X.Y.y branch for your version (e.g., rpi-6.12.y).
Clone the kernel source (adjust the branch to match your kernel version):
Replace rpi-6.12.y
with the correct branch for your version if different.
sudo git clone --depth=1 --branch rpi-6.12.y [<https://github.com/raspberrypi/linux.git>](<https://github.com/raspberrypi/linux.git>) /usr/src/$(uname -r)