LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
LinkBack Search this Thread
Old 09-21-2005, 03:18 PM   #1
sadarax
Member
 
Registered: Sep 2005
Distribution: Ubuntu
Posts: 249

Rep: Reputation: 30
What's are kernel headers / source-tree?


I am wondering what are kernel headers, and a kernel source tree exactly> Is the source tree the same as just a regular kernel source? Also, if one wanted to compile a kernel or add a module to a kernel, one usually needs the kernel source, but with the kernel headers do?
 
Old 09-21-2005, 03:44 PM   #2
Komakino
Senior Member
 
Registered: Feb 2004
Location: Somerset, England
Distribution: Slackware 10.2, Slackware 10.0, Ubuntu 9.10
Posts: 1,938

Rep: Reputation: 53
The kernel headers are the C language .h files relevant to the kernel, i.e. those used to build the kernel and those used when compiling programs (or more likely, drivers) that use aspects of the kernel. They are NOT enough to build a new kernel. For that you will need the kernel source (which is the same as the source tree) as this contains not only the headers, but the actual C source files containing the code used to compile into a kernel.

If you want a completely up to date kernel then kernel.org is the place to go. If your distro heavily patches their kernel then you might just want to use their source which is usually available on the install CD.
 
Old 09-21-2005, 06:29 PM   #3
tkedwards
Senior Member
 
Registered: Aug 2004
Location: Munich, Germany
Distribution: Opensuse 11.2
Posts: 1,549

Rep: Reputation: 49
Quote:
If you want a completely up to date kernel then kernel.org is the place to go. If your distro heavily patches their kernel then you might just want to use their source which is usually available on the install CD.
Yeah if you need the kernel source to install a driver then you must get it from your distro's package management system, just getting a vanilla kernel from kernel.org will not match your running kernel.
 
Old 09-21-2005, 08:13 PM   #4
primo
Member
 
Registered: Jun 2005
Posts: 542

Rep: Reputation: 34
The kernel headers should be the ones in /usr/src/linux-*/include

Some glibc packages (specially rpm ones) install linux headers in /usr/include/linux in a very improper way that could cause problems if you install +1 kernels, worse if one is 2.4 and another 2.6

So the correct way would be to use uname(1) and use
/usr/src/linux-`uname -r`/include instead of <linux/version.h>

These days, some RPM distributions have a script named kheader that just solves this problem for /usr/src/linux/include/version.h and autoconf.h

The proper way would be to handle the linux symlink in /usr/src and /usr/include/linux entirely
 
Old 10-07-2005, 11:02 AM   #5
win32sux
Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 371Reputation: 371Reputation: 371Reputation: 371
hi, can anyone point me to a howto where it shows how to make a kernel headers package??

i wanna recompile my kernel and stuff, but IIRC the nvidia installer will complian if the headers you have at compile time aren't the same version of your current kernel (which is kinda odd, no?)...

so i would like to make a new kernel-headers package when i recompile the kernel (using the latest 2.4 prepatch), then i would recompile glibc with the new headers, and then i would do the nvidia install, etc...

i've made a kernel headers package before but i seem to have forgotten how it's done...

any pointers would be greatly appreciated...

thanks...
 
Old 10-07-2005, 02:00 PM   #6
win32sux
Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 371Reputation: 371Reputation: 371Reputation: 371
after looking at the contents of the official slackware kernel-headers i'm starting to think it's just a matter of packaging the contents of $SRC/include/linux and $SRC/include/asm-i386 (to /usr/include), where $SRC is the source code you just compiled your kernel with...

does that sound about right, or am i trippin'??

 
Old 10-07-2005, 02:12 PM   #7
jong357
Senior Member
 
Registered: May 2003
Location: Columbus, OH
Distribution: DIYSlackware
Posts: 1,914

Rep: Reputation: 52
Just copy /usr/src/linux-$VERSION/include/{linux,asm-i386} $PKG/usr/include
ln -sf $PKG/usr/include/asm-i386 $PKG/usr/include/asm

That's pretty much it...

Code:
#!/bin/sh

CWD=`pwd`
TMP=/tmp
PKG=$TMP/package-kernel-headers
# If your using 2.4.32-rc1 as stated, what's that make our PKGVER? :-)
# Not such a hot idea IMO....
VERSION=2.4.31
PATCHVER=2.4.32-rc1
PKGVER=2.4.32_rc1
ARCH=i386
BUILD=1

rm -rf $PKG
mkdir -p $PKG/usr/include

cd $TMP
rm -rf linux-$VERSION
tar xjf $CWD/linux-$VERSION.tar.bz2
cd linux-$VERSION
bzip2 -dc $CWD/patch-$PATCHVER.bz2 | patch -p1
cp -R include/asm-$ARCH $PKG/usr/include/asm-$ARCH
cp -R include/linux $PKG/usr/include
( cd $PKG
  chown -R root.root .
  find usr/include/{asm-$ARCH,linux} -type d -exec chmod 755 {} \;
  find usr/include/{asm-$ARCH,linux} -type f -exec chmod 644 {} \; )
( cd $PKG/usr/include
  ln -sf asm-$ARCH asm )

mkdir -p $PKG/install
cat << EOF > $PKG/install/slack-desc
# HOW TO EDIT THIS FILE:
# The "handy ruler" below makes it easier to edit a package description.  Line
# up the first '|' above the ':' following the base package name, and the '|'
# on the right side marks the last column you can put a character in.  You must
# make exactly 11 lines for the formatting to be correct.  It's also
# customary to leave one space after the ':'.

              |-----handy-ruler------------------------------------------------------|
kernel-headers: kernel-headers (Linux kernel include files)
kernel-headers:
kernel-headers: These are the include files from the Linux kernel.
kernel-headers:
kernel-headers: You'll need these to compile most system software for Linux.
kernel-headers:
kernel-headers:
kernel-headers:
kernel-headers:
kernel-headers:
kernel-headers:
EOF

# Build the package:
cd $PKG
makepkg -l y -c n $TMP/kernel-headers-$PKGVER-$ARCH-$BUILD.tgz

Last edited by jong357; 10-07-2005 at 02:20 PM.
 
Old 10-07-2005, 02:26 PM   #8
Komakino
Senior Member
 
Registered: Feb 2004
Location: Somerset, England
Distribution: Slackware 10.2, Slackware 10.0, Ubuntu 9.10
Posts: 1,938

Rep: Reputation: 53
Quote:
Originally posted by win32sux
hi, can anyone point me to a howto where it shows how to make a kernel headers package??

i wanna recompile my kernel and stuff, but IIRC the nvidia installer will complian if the headers you have at compile time aren't the same version of your current kernel (which is kinda odd, no?)...

so i would like to make a new kernel-headers package when i recompile the kernel (using the latest 2.4 prepatch), then i would recompile glibc with the new headers, and then i would do the nvidia install, etc...

i've made a kernel headers package before but i seem to have forgotten how it's done...

any pointers would be greatly appreciated...

thanks...
OK, there seems to be some confusion. The kernel source in /usr/src/linux should match the currently running kernel or the nvidia installer will complain. The kernel headers in /usr/include/linux should match the kernel version that glibc was compiled against.
 
Old 10-07-2005, 02:29 PM   #9
jong357
Senior Member
 
Registered: May 2003
Location: Columbus, OH
Distribution: DIYSlackware
Posts: 1,914

Rep: Reputation: 52
Quote:
Originally posted by Komakino
OK, there seems to be some confusion. The kernel source in /usr/src/linux should match the currently running kernel or the nvidia installer will complain. The kernel headers in /usr/include/linux should match the kernel version that glibc was compiled against.
Exactally.

Actually, the nvidia driver looks at /lib/modules/$(uname -r)/build and not /usr/src/linux... But yea, same idea.

I was wondering myself why you want to upgrade kernel-headers before a new glibc compile when the existing headers on slack are not even a version number away. Doesn't seem to be a point in it. If the 2.4.32-rc1 patch doesn't touch the header files, then you would be replacing the stock slack header package with an exact duplicate.... :-)

Last edited by jong357; 10-07-2005 at 02:36 PM.
 
Old 10-07-2005, 03:57 PM   #10
win32sux
Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 371Reputation: 371Reputation: 371Reputation: 371
Quote:
Originally posted by jong357
Just copy /usr/src/linux-$VERSION/include/{linux,asm-i386} $PKG/usr/include
ln -sf $PKG/usr/include/asm-i386 $PKG/usr/include/asm

That's pretty much it...

Code:
#!/bin/sh

CWD=`pwd`
TMP=/tmp
PKG=$TMP/package-kernel-headers
# If your using 2.4.32-rc1 as stated, what's that make our PKGVER? :-)
# Not such a hot idea IMO....
VERSION=2.4.31
PATCHVER=2.4.32-rc1
PKGVER=2.4.32_rc1
ARCH=i386
BUILD=1

rm -rf $PKG
mkdir -p $PKG/usr/include

cd $TMP
rm -rf linux-$VERSION
tar xjf $CWD/linux-$VERSION.tar.bz2
cd linux-$VERSION
bzip2 -dc $CWD/patch-$PATCHVER.bz2 | patch -p1
cp -R include/asm-$ARCH $PKG/usr/include/asm-$ARCH
cp -R include/linux $PKG/usr/include
( cd $PKG
  chown -R root.root .
  find usr/include/{asm-$ARCH,linux} -type d -exec chmod 755 {} \;
  find usr/include/{asm-$ARCH,linux} -type f -exec chmod 644 {} \; )
( cd $PKG/usr/include
  ln -sf asm-$ARCH asm )

mkdir -p $PKG/install
cat << EOF > $PKG/install/slack-desc
# HOW TO EDIT THIS FILE:
# The "handy ruler" below makes it easier to edit a package description.  Line
# up the first '|' above the ':' following the base package name, and the '|'
# on the right side marks the last column you can put a character in.  You must
# make exactly 11 lines for the formatting to be correct.  It's also
# customary to leave one space after the ':'.

              |-----handy-ruler------------------------------------------------------|
kernel-headers: kernel-headers (Linux kernel include files)
kernel-headers:
kernel-headers: These are the include files from the Linux kernel.
kernel-headers:
kernel-headers: You'll need these to compile most system software for Linux.
kernel-headers:
kernel-headers:
kernel-headers:
kernel-headers:
kernel-headers:
kernel-headers:
EOF

# Build the package:
cd $PKG
makepkg -l y -c n $TMP/kernel-headers-$PKGVER-$ARCH-$BUILD.tgz
hey thanks a lot man!!! you went above and beyond with the script!!! thanks!!!

Quote:
Originally posted by Komakino
OK, there seems to be some confusion. The kernel source in /usr/src/linux should match the currently running kernel or the nvidia installer will complain. The kernel headers in /usr/include/linux should match the kernel version that glibc was compiled against.
no confusion about that on my part... it's just that i thought i remembered the nvidia installer complaining when the header versions weren't the same as the running kernel (even though it doesn't make sense to do so), not just the source... i know that the headers one needs to have are the ones glibc was compiled against, which made the nvidia installer's complain really weird... but then again i was probably trippin' and yeah maybe it only complains about different source versions, not the headers... or maybe it used to complain but they realized it was retarded and they eventually changed that "feature/bug" of the installer?? i could try the install with the .31 headers when i have compiled .32-rc1 to see if it complains or not... i do know that it SHOULDN'T complain, of course...

Quote:
Originally posted by jong357
Exactally.

Actually, the nvidia driver looks at /lib/modules/$(uname -r)/build and not /usr/src/linux... But yea, same idea.

I was wondering myself why you want to upgrade kernel-headers before a new glibc compile when the existing headers on slack are not even a version number away. Doesn't seem to be a point in it. If the 2.4.32-rc1 patch doesn't touch the header files, then you would be replacing the stock slack header package with an exact duplicate.... :-)
yeah, i'm aware that there's really no technical reason for recreating the kernel-headers package... however i had this (possibly false) memory of the nvidia installer complaining when the kernel headers were a different version from the running kernel (even though it doesn't make sense to complain about that) and so that was the original reason i wanted to make a new headers package when i recompiled the new kernel (so the versions would match)... now it seems like it's just for the sake of education and for the psychological well-being that unexperienced folks like myself get when we do these pointless things...

BTW, i should mention that i will be recompiling glibc (or attempting to ) with the new .32-rc1 headers:

http://www.linuxquestions.org/questi...postid=1889331

thanks for all the great replies people!!!


Last edited by win32sux; 10-07-2005 at 04:02 PM.
 
  


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 On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to integrate driver source into kernel source tree zhchang Linux - Software 5 11-23-2005 12:34 AM
where is kernel source tree ? overproof Mandriva 2 04-07-2005 03:28 PM
Kernel source tree ... Solstice Mandriva 6 10-05-2004 12:30 PM
where is linux source build directory/kernel source tree? webazoid Linux - Software 2 07-01-2004 08:37 PM
No kernel source tree? rhuntley12 Debian 3 04-14-2004 10:12 PM


All times are GMT -5. The time now is 10:35 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration