LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-06-2006, 04:48 PM   #1
stevesk
Member
 
Registered: Dec 2004
Distribution: Slackware-current
Posts: 207

Rep: Reputation: 30
Kernel Headers FAQ


Hey people! Does anyone knows any website which explains well about Kernel Headers, like what are them for, where are them, how to update them, etc.? Thanks!
 
Old 07-06-2006, 06:22 PM   #2
bigjohn
Senior Member
 
Registered: Jun 2002
Location: UK .
Distribution: *buntu (usually Kubuntu)
Posts: 2,682
Blog Entries: 9

Rep: Reputation: 45
Quote:
Originally Posted by stevesk
Hey people! Does anyone knows any website which explains well about Kernel Headers, like what are them for, where are them, how to update them, etc.? Thanks!
google is your friend! if you have the "kernel-headers" installed (a.k.a. kernel-sources, depending on the distro) then it may, or may not, appear as an update/upgrade when you change kernels (for whatever the reason).

they are traditionally needed to install things like the nvidia driver - the driver package needs the kernel headers/sources to make the module for your kernel so that it will run the nvidia proprietary driver.

I notice you list slackware as your distro, so I'm sorry I can't help as to what the package might be called that is probably available. Though Mandriva tended to call them kernel-sources, whereas SuSE seemed to call them kernel-headers.


Erm, I think thats right!

TTFN

John
 
Old 07-06-2006, 09:08 PM   #3
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 75
Sanitized kernel headers, as they're often called, are very similar to the actual header files used in a kernel. Headers are files used (mostly) in C that (usually) describe interfaces to a library (or any sort of thing you might link to but you don't need/want to see the entire code, only interfaces). The linux headers are those used by the kernel when it was compiled. So if the kernel provides a special interface for user programs, the userspace programs will know how to access it. A great difference between the kernel-version and the version of the headers against which your programs were compiled is bad, because: the kernel might provide an interface in a certain way, but when the program was compiled, it was told the interface is provided differently. The program might try to access it the other way, and things will break.

Here are the steps a distro usually takes when making the linux-headers (or equivalent):
  1. Compile a kernel that the distro will use in its `stable' release.
  2. After configuration/compilation/testing to make sure the kernel is able to handle many different setups, copy the include/linux and include/asm directories into somewhere like /usr/include
  3. Go through and remove things only applicable in kernel-space (this is mostly done with a script, but there is also some fine-toothed combing by hand)
  4. Compile all your binary packages with those headers
  5. If anything breaks (because of the linux-headers), you try to fix the headers, and then recompile all binaries against the newer headers.
  6. Now that you've proven your sanitized kernel headers are truly sane (at least for the kind of setups your distro uses), you make them into a package to release to your followers as being stable.

Very few of the programs compiled will/should actually need the kernel's headers (most only need POSIX-compliant headers). The few that will are (nonportable) programs that need intimate access to certain kernel internals (e.g., iptables). Other `portable' binaries will compile fine without the kernel's headers, but might make use of them (optimizations, etc.) if they are there (e.g., libgmp). The only other things that will need the kernel's headers are loadable modules (such as nvidia). Since these are part of the kernel, a kernel-change will require recompilation with the EXACT same (unsanitized) headers with which the kernel was compiled. Other programs, even things intimate with the kernel like ifconfig, will be fine when using old headers on a newer kernel (as long as the headers are not `too old').

Another thing to note is that the header files do absolutely nothing for you if all you use is precompiled binaries. If a program uses the headers, any information from them will be taken only at compile-time.

The whole kernel-headers stuff is kind of confusing since each distro does it a slightly different way. Also, ususally there's no way to tell what version of the headers a given program was compiled against (only much broader things such as ABI version).
 
Old 07-07-2006, 10:38 PM   #4
stevesk
Member
 
Registered: Dec 2004
Distribution: Slackware-current
Posts: 207

Original Poster
Rep: Reputation: 30
John: Well, I agree with you that Google is my friend, but I had already Googled and didn't find any good explanation, not even in the site you told me. I challenge you to find by google an explanation as good as osor did above . In Slackware it is kernel-headers-[kernel-version].tgz, located in package series "d" (just for reference heheheheh).

Osor: Wow, thanks SO MUCH for all the explanation...I will even save it in a file for reference! It was really a valuable one, I didn't find on Google not even 1/10 part of it. I see that you use LFS, you should understand a lot about it. So here it comes 2 questions:

1. Why does a new kernel needs the old one's headers when I will compile it? Is there anything I can do to avoid that? Like, in LFS, you possibily must do your own headers, so how do you do?

2. I didn't understand well the step 3...

Thanks so much again for the text!
 
Old 07-08-2006, 10:45 AM   #5
bigjohn
Senior Member
 
Registered: Jun 2002
Location: UK .
Distribution: *buntu (usually Kubuntu)
Posts: 2,682
Blog Entries: 9

Rep: Reputation: 45
Quote:
Originally Posted by stevesk
John: Well, I agree with you that Google is my friend, but I had already Googled and didn't find any good explanation, not even in the site you told me. I challenge you to find by google an explanation as good as osor did above . In Slackware it is kernel-headers-[kernel-version].tgz, located in package series "d" (just for reference heheheheh).
Ah, I was of the view that the
Quote:
Description:Kernel-headers includes the C header files for the Linux kernel. The header files define structures and constants that are needed for building most standard programs. The header files are also needed for rebuilding the kernel. (from rpm description)
line might have answered your question.

Of course, it depends on how much depth you need, to satisfy your quest.

Osor obviously knows one hell of a lot more about linux that I do (Ha! my linux knowledged could be written on the back of a very small postage stamp).

Don't suppose it really matters stevesk, you got quite a good answer from Osor.

Good luck with your endeavours my friend.

regards

John
 
Old 07-08-2006, 05:29 PM   #6
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 75
Please excuse my long posts. Sometimes I start babbling and can't stop. I don't understand everything as much as it seems, I just have a problem with long posting.
Quote:
Originally Posted by stevesk
1. Why does a new kernel needs the old one's headers when I will compile it? Is there anything I can do to avoid that? Like, in LFS, you possibily must do your own headers, so how do you do?
A new kernel doesn't need the headers of the old one. A kernel source package (from kernel.org) comes with its own headers. Upon configuring the kernel, a few (maybe just two) of these header files are modified to reflect the options you chose. So a kernel comes with everything it needs (well, except for compiler and linker). Anything else that will essentially be part of a running kernel, (e.g., third party modules such as nvidia's) need access to the exact same files as were used to compile the kernel (instead of thinking of them as userspace programs, think of them as extensions to the kernel. obviously, it would make sense to use kernel headers).

Often a program wants to use features of the kernel directly. The normal way for doing this (in normal programs and also in earlier kernels) is just to use the same files themselves. The problem is that the kernel developers write kernel headers for themselves to use (in kernelspace). These have a lot of stuff userspace programs will never need, and stuff that may seem slighly strange to userspace programs. But userspace programs want to use facilities of the kernel, so someone decided to clean up the header files to make them suitable to use in normal programs. What about people who switch between three or four different kernels? If they need to be compiled with the kernel's exact headers, you would need three or four versions of each program (one place you see this is with drivers, which again, are not programs. For example, if I run three different kernels sharing a common root directory, I would need to compile the nvidia drivers three separate times in order for me to have decent graphics in each scenario). This is also a lot of work for distro people (sanitize each releases code). Therefore, what usually goes on (as I said before), is that a stable kernel release is taken. The headers are sanitized and distributed. As long as the difference between actual kernel version and userspace headers is small, the system should be stable.

Quote:
Originally Posted by stevesk
Osor:Is there anything I can do to avoid that? Like, in LFS, you possibily must do your own headers, so how do you do?

2. I didn't understand well the step 3...

Thanks so much again for the text!
In LFS especially, you really don't want to switch the kernel headers. Then, if there is a possibility for breakage, it not only exists between the kernel and the userspace programs, but also between the userspace programs compiled before and after the switch. The only thing that one normally does is sometimes update certain headers that implement functionality that you know is in your kernel, but isn't detailed in your userspace headers as long as you know exactly what program you want to have that uses the said functionality (inotify comes to mind).

As for getting headers for the system, I certainly don't hand-sanitize them. There are many ways to get them (besides just going with one from a distro vendor). For awhile, there was a guy named Mazur who provided a good set of headers, but he no longer has the time. There are other numerous scripts around the internet that get rid of most unwanted stuff. I was a little vague on the details before, but here's something from a more authoritative source (from the comments of a header-cleaning script written by the CLFS guys):
Code:
49 	# Conversion Process
50 	#
51 	# Removal of __KERNEL__ - These tags are only during the build of the kernel
52 	#
53 	# Conversion u and s variables to userspace variables is the following link
54 	# for more information http://www.linuxdevices.com/articles/AT5340618290.html
55 	#
56 	# Removal of <linux/config.h> - Not needed for userspace contains kernel build
57 	# information.
58 	#
59 	# Conversion of linux to __linux__ - converts to a userspace usable
60 	#
61 	# Removal of __iomem
62 	# for more information http://lwn.net/Articles/102232/
63 	#
64 	# version.h is created so that all the kernel versioning information
65 	# is available
66 	#
67 	# compiler.h is removed
68 	#
69 	#
70 	# I386 Specific
71 	#
72 	# Removal of <asm/processor.h> from all i386 headers.
73 	#
74 	#
75 	# MIPS Specific
76 	#
77 	# CONFIG_64BIT and CONFIG_32BIT are not defined in userspace so we use
78 	# __mips64.
79 	#
80 	# Make atomic.h the same as LLH.
81 	#
82 	#
83 	# Sparc Specific
84 	#
85 	# RAW Headers use variables from the configuration to get the PAGE SIZE
86 	# so we use a function that exists in glibc to figure it out.
87 	#
88 	#
89 	# Creation of biarch headers for multilib builds
90 	#
If you need more information, I you can look at both http://headers.cross-lfs.org and the CLFS headers mailing list.
 
Old 07-08-2006, 08:21 PM   #7
masonm
Senior Member
 
Registered: Mar 2003
Location: Following the white rabbit
Distribution: Solus
Posts: 2,254

Rep: Reputation: 47
Every time you compile a new kernel, you get new kernel headers. It's only needed to compile certain code, most often things like drivers.
 
Old 07-09-2006, 04:38 AM   #8
bigjohn
Senior Member
 
Registered: Jun 2002
Location: UK .
Distribution: *buntu (usually Kubuntu)
Posts: 2,682
Blog Entries: 9

Rep: Reputation: 45
Quote:
Originally Posted by masonm
Every time you compile a new kernel, you get new kernel headers. It's only needed to compile certain code, most often things like drivers.
Hum? wondered about that one, because when I ran mandriva, it would install the new kernel version via URPMI but I'd always have to make sure that it got the kernel-sources seperately - it didn't by default.

Not sure about this Kubuntu I'm running now!

Does it do that automatically with Slack ??

{edit}or am I understanding this wrongly as you mentioned the "c" word (compile) as opposed to installing something pre-compiled ???{/edit}

Last edited by bigjohn; 07-09-2006 at 04:39 AM.
 
Old 07-10-2006, 04:16 PM   #9
stevesk
Member
 
Registered: Dec 2004
Distribution: Slackware-current
Posts: 207

Original Poster
Rep: Reputation: 30
Thanks osor, I will bookmark the site. You said that a kernel doesn't need the headers of an old one, but when I tried to compile a new 2.6.X kernel using the last slackware dist. with a 2.4.X kernel, I got compilation errors on make because I didn't install the headers that came with the dist. After installing the headers, and another stuff like ncurses, everything worked fine. And I still didn't understand why... :P

Anyway, thanks for the site, I will seek more doc about the headers.

Quote:
Every time you compile a new kernel, you get new kernel headers. It's only needed to compile certain code, most often things like drivers.
How and when does it happen? When I type make modules_install or make install?
 
Old 08-03-2006, 01:38 AM   #10
stevesk
Member
 
Registered: Dec 2004
Distribution: Slackware-current
Posts: 207

Original Poster
Rep: Reputation: 30
Ok, I see that basically in my dist they copy 4 folders in 2.6 series:

/usr/src/include/asm-generic
/usr/src/include/asm-i386
/usr/src/include/linux
/usr/src/include/sound

Do you confirm that?

Edit: Yep, using x86 here.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Compilation aborted - Please read the FAQ for linux-libc-headers package ???? idardh Linux - Software 3 07-17-2006 08:31 PM
Errors Compiling Kernel 2.6 on Slackware 10.2 - Old kernel headers required? Dave S. Slackware 8 03-04-2006 01:15 AM
FAQ of Kernel changes and the impacts? brundles Linux - General 1 05-11-2005 10:59 AM
send packets with kernel routing and without kernel messing with headers bassdemon Programming 5 02-08-2005 07:29 PM
New FAQ topic: Should I edit my kernel configuration?/Should I build a custom kernel? chort *BSD 10 09-11-2004 12:15 AM


All times are GMT -5. The time now is 11:48 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration