LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 10-06-2017, 02:02 PM   #1
RandomTroll
Member
 
Registered: Mar 2010
Distribution: Slackware
Posts: 608

Rep: Reputation: 72
Why do I need my distribution's kernel headers package?


I build my kernel. If I don't have my distribution's kernel-headers package installed, the build complains about missing header files. Why aren't all the headers the kernel needs in the kernel source? The distro's version is far behind the latest kernel; I'm surprised this hasn't caused a problem.
 
Old 10-06-2017, 04:31 PM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: CentOS 6 (pre-systemd)
Posts: 2,855

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
My guess would be that when you build, you are not following the directions in the kernel source. The build should not be using any header files outside the source tree.
 
Old 10-06-2017, 05:34 PM   #3
RandomTroll
Member
 
Registered: Mar 2010
Distribution: Slackware
Posts: 608

Original Poster
Rep: Reputation: 72
I run 'make', then, as root, 'make install' - what could I be not-doing?
 
Old 10-06-2017, 10:26 PM   #4
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Debian, Mageia, and whatever VMs I happen to be playing with
Posts: 12,885
Blog Entries: 18

Rep: Reputation: 3346Reputation: 3346Reputation: 3346Reputation: 3346Reputation: 3346Reputation: 3346Reputation: 3346Reputation: 3346Reputation: 3346Reputation: 3346Reputation: 3346
This thread from Stack Exchange should help: https://unix.stackexchange.com/quest...kernel-headers

As I rather clumsily interpret it, when you compile from sources, the build process needs to consult the kernel headers so that certain functions are properly defined in the compiled code.
 
Old 10-06-2017, 11:21 PM   #5
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 3,339
Blog Entries: 1

Rep: Reputation: 693Reputation: 693Reputation: 693Reputation: 693Reputation: 693Reputation: 693
If you need to compile something against your kernel, you need the headers. Which is as far as the compiler is concerned, whatever /lib/modules/$(uname -r)/build points at.

$ ls -al /lib/modules/$(uname -r)/build

If you don't need to compile anything that requires it, then you don't need it. Sadly a lot of proprietary drivers do need it.
 
1 members found this post helpful.
Old 10-06-2017, 11:23 PM   #6
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Debian, Mageia, and whatever VMs I happen to be playing with
Posts: 12,885
Blog Entries: 18

Rep: Reputation: 3346Reputation: 3346Reputation: 3346Reputation: 3346Reputation: 3346Reputation: 3346Reputation: 3346Reputation: 3346Reputation: 3346Reputation: 3346Reputation: 3346
Thanks, Shadow 7. I have known that you generally need the headers to compile from sources, but your post adds clarity as to why.
 
Old 10-08-2017, 04:53 PM   #7
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 8,706
Blog Entries: 4

Rep: Reputation: 3030Reputation: 3030Reputation: 3030Reputation: 3030Reputation: 3030Reputation: 3030Reputation: 3030Reputation: 3030Reputation: 3030Reputation: 3030Reputation: 3030
Kernel headers are ordinarily packaged separately from the kernel source (but should be listed as a dependency of the kernel source), because many pieces of software might need to know "what a particular data-structure exposed or used by the kernel looks like." So, they need to be able to reference the correct version of specified kernel header-files, but they have no need of the kernel source-code itself.

It is quite common to find kernel-headers installed, and relatively rare to see the source-code being needed.
 
Old 10-12-2017, 03:00 PM   #8
RandomTroll
Member
 
Registered: Mar 2010
Distribution: Slackware
Posts: 608

Original Poster
Rep: Reputation: 72
This thread went astray. I meant to ask, 'Why do I need the kernel headers package of my distribution to build the kernel, the source for which I fetch from kernel.org?' - not why do I need it to compile other software.

It occurred to me that I remove the kernel-headers package removepkg un-removes only conflicting files installed by another package, that it would have no compunction against removing a file installed by a non-package. So I removed the package then ran a script that read that package's file list then linked the kernel source's header files into the package's target locations. Today 4.13.6 was released, but it wouldn't build because it couldn't find /usr/include/linux/limits.h; the /usr/include/linux/limits.h in the package is not the same as any in the kernel source. It quit at the first fatal error; it's possible other files were necessary.

The package is on 4.9.53. The only way this makes sense that this isn't in the kernel is if this refers to something other than the kernel.
 
Old 10-13-2017, 04:46 AM   #9
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 3,339
Blog Entries: 1

Rep: Reputation: 693Reputation: 693Reputation: 693Reputation: 693Reputation: 693Reputation: 693
You need the headers for the kernel you are currently running. As that is what other things will compile against without overriding defaults. Changes are good that you are running a kernel provided by the distro, so you need the distros kernel header package.
 
Old 10-13-2017, 07:01 AM   #10
hazel
Senior Member
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: Debian, Crux, LFS, AntiX, NuTyX
Posts: 1,490
Blog Entries: 2

Rep: Reputation: 639Reputation: 639Reputation: 639Reputation: 639Reputation: 639Reputation: 639
I would say rather that you need the headers your glibc was built against, if you are going to build anything else. That's why distros package the headers separately. You can run a live version of a different kernel without having headers for it.

If you build a kernel from source (e.g. from kernel.org), it comes with all the headers you need. But that might not be the case with a distro-supplied kernel.
 
Old 10-13-2017, 04:19 PM   #11
RandomTroll
Member
 
Registered: Mar 2010
Distribution: Slackware
Posts: 608

Original Poster
Rep: Reputation: 72
Quote:
Originally Posted by Shadow_7 View Post
You need the headers for the kernel you are currently running.
I have those. My build fails because it lacks headers provided by the kernel-headers package of an older kernel.

Quote:
Originally Posted by Shadow_7 View Post
Changes are good that you are running a kernel provided by the distro, so you need the distros kernel header package.
Chances have nothing to do with it. I download kernel source from kernel.org, as I wrote.

Quote:
Originally Posted by hazel View Post
I would say rather that you need the headers your glibc was built against
I have those.

Quote:
Originally Posted by hazel View Post
If you build a kernel from source (e.g. from kernel.org), it comes with all the headers you need. But that might not be the case with a distro-supplied kernel.
As I wrote, I download source from kernel.org, and it won't build unless I have header files absent from it.
 
Old 10-13-2017, 09:18 PM   #12
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 3,339
Blog Entries: 1

Rep: Reputation: 693Reputation: 693Reputation: 693Reputation: 693Reputation: 693Reputation: 693
The kernel sources from kernel.org have "special" build steps. The usual ./configure && make && make install will fail. If you are building the sources from kernel.org, then you don't need the headers, as the sources ARE the headers. At least once you build the kernel and after you boot it. Caveat, you probably need about 10GB+ of free space to build the kernel if you start with the .config that goes with your distros kernel. It might be failing because you ran out of space.
 
1 members found this post helpful.
Old 10-14-2017, 02:51 AM   #13
hazel
Senior Member
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: Debian, Crux, LFS, AntiX, NuTyX
Posts: 1,490
Blog Entries: 2

Rep: Reputation: 639Reputation: 639Reputation: 639Reputation: 639Reputation: 639Reputation: 639
Shadow has made a point that I would not have thought of making. When you build a kernel from source, you must use the kernel's own configuration tools. First use make defconfig to create a configuration file with suitable defaults. Then make menuconfig to configure it more precisely for your hardware. Only then do you use make.

Did you do that?
 
Old 10-15-2017, 05:57 PM   #14
RandomTroll
Member
 
Registered: Mar 2010
Distribution: Slackware
Posts: 608

Original Poster
Rep: Reputation: 72
If I've made the mistake of running make without a .config in place make has run 'make config' - something I never want to do again. I have a .config from the previous build (I've been patching for years); if the new kernel has new parameters for .config it begins by asking me how I want to set them.

4.13.7 showed up yesterday. I did a better job of linking its headers into /usr/include and was able to build without the kernel-headers package. I think the error I made last time was to link to /usr/src/linux-4.13.5, which had just become /usr/src/linux-4.13.6. I keep /usr/src/linux linked to /usr/src/linux-$version so should use that instead.
 
Old 10-16-2017, 05:09 AM   #15
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 3,339
Blog Entries: 1

Rep: Reputation: 693Reputation: 693Reputation: 693Reputation: 693Reputation: 693Reputation: 693
There's various make options for the kernel sources. I think $(make symlinks) handles the */include/* stuff, it's been a while and I don't have sources currently installed. I normally don't need to use custom kernels these days, and if I do it's simpler to just run arch IMO. There's a whole ./documentation/ or other things in the sources that describes things. Or read the Makefile.

Also I tend to cp the /boot/config for the current kernel to .config and make oldconfig. Which might be /proc/kconfig.gz or something depending on your system (raspbian). So $(zcat /proc/kconfig.gz > .config) if that's the case with various other tricks.

Last edited by Shadow_7; 10-16-2017 at 05:12 AM.
 
  


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
kernel-package fails to compile kernel headers on (*)Ubuntu 16.04.2 donald3.heckel Linux - Software 2 05-26-2017 09:44 PM
[SOLVED] Updated to kernel 3.0.4 but now source package can not find kernel headers. ReaperX7 Slackware 2 10-03-2011 07:48 PM
Automatic removal of kernel headers package when kernel packages are removed bgoodr Debian 3 12-30-2008 09:14 PM
I need the kernel headers package for 2.6.13-7smp Thaidog Linux - General 2 06-25-2006 03:24 PM
kernel-headers package? mike2265 Linux - Newbie 1 03-17-2005 05:02 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 04:44 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