I am trying to build a sample Linux kernel module using the following command in my makefile on my Raspberry Pi 3B+ running the latest Raspbian Buster OS updated with sudo apt-get dist-upgrade:
make -C /lib/modules/$(shell uname -r)/build/ M=$(PWD) modules
I get the following output:
make -C /lib/modules/4.19.57-v7+/build/ M=/home/pi/isr_test modules
make[1]: *** /lib/modules/4.19.57-v7+/build/: No such file or directory. Stop.
make: *** [Makefile:4: all] Error 2
I tried installing linux headers using this command:
sudo apt-get install linux-headers-$(uname -r)
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package linux-headers-4.19.57-v7
E: Couldn't find any package by glob 'linux-headers-4.19.57-v7'
E: Couldn't find any package by regex 'linux-headers-4.19.57-v7'
I tried looking for Linux headers using this command, and it looks like they are installed:
dpkg -l | grep kernel-headers
ii raspberrypi-kernel-headers 1.20190718-1 armhf Header files for the Raspberry Pi Linux kernel
I tried looking in the /lib/modules directory:
ls /lib/modules
4.19.58+ 4.19.58-v7+ 4.19.58-v7l+
See how there's no 4.19.57 there?
Also, under /usr/src, all I have is these directories:
ls /usr/src
linux-headers-4.19.58+ linux-headers-4.19.58-v7+ linux-headers-4.19.58-v7l+ sense-hat
Again, nothing for 4.19.57.
For the current OS, here's what I get when I run uname -r:
uname -r
4.19.57-v7+
When I change my makefile to point to the 4.19.58-v7+ instead of 4.19.57-v7+, I get my module to build with no issues.
I'm expecting to see folders with 4.19.57 in their names, but all I get is 4.19.58 (see the folders above). How can I get the Linux header files that match my Linux kernel version? Or does it not matter?
APT::NeverAutoRemovesection in the "/etc/apt/apt.conf.d/01autoremove-kernels" file, which is updated by the kernel postinstall script "/etc/kernel/postinst.d/apt-auto-removal". - Ian Abbott