LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   What's are kernel headers / source-tree? (https://www.linuxquestions.org/questions/linux-general-1/whats-are-kernel-headers-source-tree-365685/)

sadarax 09-21-2005 03:18 PM

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?

Komakino 09-21-2005 03:44 PM

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.

tkedwards 09-21-2005 06:29 PM

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.

primo 09-21-2005 08:13 PM

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

win32sux 10-07-2005 11:02 AM

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...

win32sux 10-07-2005 02:00 PM

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'??


jong357 10-07-2005 02:12 PM

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


Komakino 10-07-2005 02:26 PM

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.

jong357 10-07-2005 02:29 PM

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.... :-)

win32sux 10-07-2005 03:57 PM

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!!!



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