Where exactly is the file linux/kernel.h?
Solution 1
The linux/kernel.h
header which gets used for module builds is the header which is part of the kernel source. When modules are built in the kernel source tree, that’s the version which is used.
For external module builds, the build process looks for the header in /lib/modules/$(uname -r)/build/include/linux/sched.h
. That file is provided by kernel header packages, e.g. on Debian derivatives, the linux-headers-$(uname -r)
package.
The /usr/include/linux/kernel.h
is intended for user processes, not for kernel modules.
The printk
priority macros now live in linux/printk.h
and linux/kern_levels.h
. I’m guessing you’re reading the original guide, which is based on the 2.6 kernel series; for modern kernels you should read the updated guide (currently for 5.6.7).
Solution 2
On my Mint 18.x system with the build-essential
BUT not any full source tree installed -
user@localhost:~ $ locate kernel.h | grep \/kernel.h$
/usr/include/linux/kernel.h
/usr/src/linux-headers-4.4.0-21/include/linux/kernel.h
/usr/src/linux-headers-4.4.0-21/include/uapi/linux/kernel.h
/usr/src/linux-headers-4.4.0-21-generic/include/config/debug/kernel.h
/usr/src/linux-headers-4.4.0-21-generic/include/config/firmware/in/kernel.h
/usr/src/linux-headers-4.4.0-53/include/linux/kernel.h
/usr/src/linux-headers-4.4.0-53/include/uapi/linux/kernel.h
/usr/src/linux-headers-4.4.0-53-generic/include/config/debug/kernel.h
/usr/src/linux-headers-4.4.0-53-generic/include/config/firmware/in/kernel.h
/usr/src/linux-headers-4.8.0-53/include/linux/kernel.h
/usr/src/linux-headers-4.8.0-53/include/uapi/linux/kernel.h
/usr/src/linux-headers-4.8.0-53-generic/include/config/debug/kernel.h
/usr/src/linux-headers-4.8.0-53-generic/include/config/firmware/in/kernel.h
Per Jeff's comment on your question, I would assume that most times /usr/include/linux/kernel.h
is what will be used,
I'm sure if you extract a kernel tree tarball it may have another copy in its directory structure as well. A quick check shows them all as being different sizes... or empty files.
Solution 3
the answer to this might significantly depend on the linux distribution... SUSE/SLES vs RHEL/Centos/Fedora vs debian vs mint and so on,
and could it also differ based on RPM flavors of linux distros vs debian ?
in any case my experience is mostly with SLES version 11.4, and for that I can vouch for
/usr/src/linux/include/linux/kernel.h
where for me /usr/src/linux -> /usr/src/linux-3.0.101-108.21
uname -r for me returns 3.0.101-108.21-default
as I update the kernel to newer versions, the soft link changes accordingly along with kernel.h. I think it is safe to say if you are looking for the kernel module version of kernel.h
it will be under some folder related to uname -r
and be part of the kernel source package for your linux distribution.
Related videos on Youtube
firedrillsergeant
Updated on September 18, 2022Comments
-
firedrillsergeant over 1 year
I am reading through Salzman's Linux Kernel Module Programming Guide, and I was wondering about where the file linux/kernel.h is located. I couldn't find it with
find
. Or rather the files I found did not have anyprintk
priority macros in them. -
muru about 6 years
locate '*/kernel.h'
is how you can getlocate
to match the exact filename (also,locate
supports regexes as well). (I'm assumingmlocate
given it's Linux Mint)