The headers should usually be installed using sudo apt install raspberrypi-kernel-headers –y
You'll see the headers installed at /usr/src
If you don't see the headers that correspond to your current kernel source uname -r
:
Install dependencies for rpi-source
sudo apt install git bc bison flex libssl-dev
Install your rpi-source
sudo wget https://raw.githubusercontent.com/RPi-Distro/rpi-source/master/rpi-source -O /usr/local/bin/rpi-source && sudo chmod +x /usr/local/bin/rpi-source && /usr/local/bin/rpi-source -q --tag-update
Run
rpi-source
After this you'll see two folders. One of them is a symbolic link to the other named linux-{sha-number to git commit pointing to kernel version}
. e.g. linux-1f9874a5435d6c3fd94a2ad00823d85cb59fc0b4
Move this folder to /usr/src/ where kernel headers should be located on your Raspberry Pi and rename it linux
:
sudo mv linux-{sha-number} /usr/src/linux
Create symbolic links after removing the ones created by rpi-source in /lib/modules/$(uname -r)
:
cd /usr/src
sudo ln -s linux linux-headers-$(uname -r)
sudo rm -rf /lib/modules/$(uname -r)/build /lib/modules/$(uname -r)/source
sudo ln -s /usr/src/linux /lib/modules/$(uname -r)/build
sudo ln -s /usr/src/linux /lib/modules/$(uname -r/source
Let me know if this works and if there's a better way of course