<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
>
<channel>
	<title>G-Loaded Journal &#187; Headers</title>
	<atom:link href="http://www.g-loaded.eu/tag/headers/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.g-loaded.eu</link>
	<description>An open-source software and technology related journal</description>
	<lastBuildDate>Mon, 05 Dec 2011 19:55:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
		<item>
		<title>The Complete Fedora Kernel Headers</title>
		<link>http://www.g-loaded.eu/2005/12/14/the-complete-fedora-kernel-headers/</link>
		<comments>http://www.g-loaded.eu/2005/12/14/the-complete-fedora-kernel-headers/#comments</comments>
		<pubDate>Wed, 14 Dec 2005 20:19:32 +0000</pubDate>
		<dc:creator>George Notaras</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Fedora]]></category>
		<category><![CDATA[Headers]]></category>
		<category><![CDATA[HOWTO]]></category>
		<category><![CDATA[Kernel]]></category>
		<guid isPermaLink="false">http://www.g-loaded.eu/?p=122</guid>
		<description><![CDATA[The official fedora <code>kernel-devel</code> package does not include the complete kernel headers. This should not be a problem in most cases when compiling third party modules, but there are times that one or more of these missing headers are absolutely needed. This document outlines a method to obtain the complete kernel headers for your <strong>currently running kernel</strong> in Fedora Core by using the kernel <strong>SRPM</strong> package without compiling the kernel.]]></description>
			<content:encoded><![CDATA[<p>The official <strong>fedora</strong> <strong>kernel-devel</strong> package does not include the complete <strong>kernel headers</strong>. This should not be a problem in most cases when compiling third party modules, but there are times that one or more of these missing headers are absolutely needed. This document outlines a method to obtain the complete kernel headers for your <strong>currently running kernel</strong> in Fedora Core by using the kernel <strong>SRPM</strong> package without compiling the kernel.<br />
<span id="more-122"></span><br />
The biggest part of the following info exists in the official Fedora Release Notes and the rest is the result of much trial and error&#8230;</p>
<h4>The Situation</h4>
<p>I bet you have been in a situation, where the compilation of a third party kernel module in Fedora does not complete, because a kernel header file is missing. The official <code>kernel-devel</code> Fedora RPM package does not include all the kernel headers. This seems to be a fact. I am not really sure what is the reason for this, but I truly believe that the developers have a good one for excluding some headers from the <code>kernel-devel</code> package.</p>
<p>However, from the user&#8217;s perspective, this situation is pretty annoying. A mere example is that a commonly needed <abbr title="Linux Infrared Remote Control">LIRC</abbr> module, <code>lirc_gpio</code>, cannot be compiled due to the fact that <code>bttv.h</code> and <code>bttvp.h</code> are not included in the <code>kernel-devel</code> package. There are a couple of other third party kernel modules I could not get compiled because of this, but I am sure there are more.</p>
<p>On the other hand, the complete <em>Fedora Kernel Source Code</em> is shipped in the kernel <strong>SRC RPM</strong>. This file can be downloaded from the official repositories. The solution to the above issues is to use the complete kernel headers contained in this SRPM package. Some preparation is required though, and this is what this document is all about.</p>
<h4>The Goal</h4>
<p>The primary goal of this article is to provide a method to prepare the Fedora kernel sources to match our <strong>currently running kernel</strong>, so that the headers can be properly used to compile modules that wouldn&#8217;t compile by using the <code>kernel-devel</code> package, because of the missing files.</p>
<p>The secondary goal is to achieve the previous goal without re-compiling the kernel. This article assumes that we want to use the <strong>default kernel configuration</strong>, so the re-compilation of the whole kernel is considered as a waste of system resources and time.</p>
<h4>The Basic Steps</h4>
<p>These steps are very well described in the <a href="http://fedora.redhat.com/docs/release-notes/fc4/errata/" title="Link the Release Notes">Fedora Core 4 Release Notes</a> (section 7.2.2.3.), but here I add some more explanation.</p>
<p>First of all, we need to download the kernel <strong>SRPM</strong> package, whose <em>version</em> and <em>release</em> match our currently running kernel. This version is shown by the following command:</p>
<pre class="console"># uname -r</pre>
<p>The rest of the article assumes that our working directory is:<br />
<code>/usr/src/redhat/</code><br />
All commands should be issued by a user and not by root, so that you do not accidentally break anything.</p>
<p>Use any method (wget, yumdownloader, any ftp or http client) you like to download the kernel SRC RPM. Just make sure you download the correct version. This is <strong>critical</strong>.</p>
<p>Next thing is to install the SRPM package. This just extracts the included files in the proper directories under <code>/usr/src/redhat/</code> or to the directory tree you use for building. It does not actually install any kernels. As a user, run:</p>
<pre class="console"># rpm -ivh kernel-$(uname -r).src.rpm</pre>
<p>This extracts the kernel source packages and the various patches in the <code>SOURCES</code> directory and the <code>spec</code> file in the <code>SPECS</code> directory. The SRC RPM file is not needed any more.</p>
<p>Next, we execute the <code>%prep</code> stage of the spec file, by issuing the following command:</p>
<pre class="console"># rpmbuild -bp --target $(arch) --rmsource --rmspec SPECS/kernel-2.6.spec</pre>
<p>This extracts the kernel source code package and applies all the Red Hat patches. All the files are placed in the <code>BUILD</code> directory. Here follows an explanation of the options:<br />
<strong>-bp</strong> : Execute only the <code>%prep</code> stage<br />
<strong>&#8211;target</strong> : Specify the architecture. You can explicitly put your architecture, instead of the $(arch) in this option. This is the same thing.<br />
<strong>&#8211;rmsource</strong> : This removes all the kernel SRC RPM related files under the <code>SOURCES</code> directory, so no unneeded files are left to the system.<br />
<strong>&#8211;rmspec</strong> : This also removes the spec file from the <code>SPECS</code> directory.</p>
<p>Now, we move to the directory containing the fedora kernel sources (2.6.14 is the version of the kernel I was using at the moment of writing):</p>
<pre class="console"># cd BUILD/kernel-2.6.14/linux-2.6.14</pre>
<p>Copy the proper kernel configuration file, that matches your architecture, from the <code>configs</code> directory and place it in our current working directory, naming it as <code>.config</code> and replacing the already existent <code>.config</code> file. For example, I used the <code>kernel-2.6.14-i686.config</code> file :</p>
<pre class="console"># cp configs/kernel-2.6.14-i686.config .config</pre>
<p>These files most probably contain the same configuration options, but we do this for completeness.</p>
<p>Next thing is to add the proper kernel release number to the <code>Makefile</code> (in directory: <code>BUILD/kernel-2.6.14/linux-2.6.14/</code>). As it is stated in the Fedora release notes, in order to &quot;<em>protect the innocent</em>&quot; the value of the <code>EXTRAVERSION</code> field is <code>-prep</code>. Open this <code>Makefile</code> in a text editor and replace the <code>-prep</code> with the <strong>release number of your currently running kernel</strong>. For example, my running kernel at the time of writing is <code>2.6.14-1.1637_FC4</code>. I replace the:</p>
<pre class="codesnp">EXTRAVERSION = -prep</pre>
<p>with :</p>
<pre class="codesnp">EXTRAVERSION = -1.1637_FC4</pre>
<p>The last action of the basic configuration is to run the following command:</p>
<pre class="console"># make oldconfig</pre>
<p>This command sets the default answers to all kernel configuration questions according to the settings of our <code>.config</code> file. This command is more relevant to kernel re-building, but won&#8217;t hurt issuing it.</p>
<h4>Extra Steps (updated Fri Dec 16, 2005)</h4>
<p>At this point, if you try to compile any third party kernel modules using this directory as the kernel source directory, you will most probably encounter errors. This is because some more preparation should be done to the kernel sources (this mainly involves the <code>include</code> directory).</p>
<p>A full compilation of the kernel would set all these things straight, but one of the goals is to avoid the compilation of the kernel to save some time. We have not modified any of the kernel configuration options or applied any extra patches, so this would be pointless anyway.</p>
<p>I remind that our current directory is:<br />
<code>/usr/src/redhat/BUILD/kernel-2.6.14/linux-2.6.14</code></p>
<p>A file, named <code>Module.symvers</code>, which contains information about the native kernel modules, needs to be present inside our current directory. This file is normally created after the native kernel modules are compiled. Since we are not building the kernel or any modules and since we have not modified the default kernel configuration, we can use the <code>Module.symvers</code> file, which is included in the official fedora <code>kernel-devel</code> RPM.</p>
<p>The presense of this file is important when we compile any third party modules using these kernel headers. If it&#8217;s not there, then our modules will not contain any dependency information, regarding the native kernel modules. This way, if the third party module depends on some native kernel modules, then you will have to load the latter manually.</p>
<p>So, <strong>copy</strong> the <code>Module.symvers</code> file from the directory, where the official fedora <code>kernel-devel</code> package is installed, into our current directory:</p>
<pre class="console"># cp /usr/src/kernels/$(uname -r)-$(arch)/Module.symvers .</pre>
<p>Finally, we issue the following command:</p>
<pre class="console"># make prepare scripts</pre>
<p>This creates:</p>
<ol>
<li>The <code>include/linux/version.h</code> file, which contains kernel versioning information.</li>
<li>The proper <code>asm</code> symlink for your platform and the <code>asm-offsets.h</code> file inside your platform&#8217;s specific <code>asm</code> directory.</li>
<li>The scripts that come with the kernel sources. These are needed when we compile third party modules using these headers.</li>
</ol>
<p>This is the proper and most complete way of preparing our headers, instead of compiling each of the files mentioned above individually (as I had written in this article before this update).</p>
<p>That should be the end of all the needed actions in order to accomplish our goal.</p>
<h4>Final Words</h4>
<p>At this point, we have a custom directory that contains:</p>
<ul>
<li>The fedora kernel sources. The kernel has not been compiled.</li>
<li>The kernel headers that match those of the <code>kernel-devel</code> RPM package with the difference that they are complete. No files are missing.</li>
</ul>
<p>This directory:<br />
<code>/usr/src/redhat/BUILD/kernel-2.6.14/linux-2.6.14</code><br />
can be moved to any place you like. Give it a proper name that includes your currently running kernel version and release. The kernel headers, contained in this directory, can be used in order to compile any third party kernel modules. The rest of the contents of the <code>/usr/src/redhat/BUILD/</code> directory, can be deleted, unless you need it.</p>
<p>Keep in mind, that if you install a different kernel in your system, <strong>this procedure has to be done again from the beginning</strong>. My next task is to create a BASH script that automates all this, so I do not have to do this by hand every time I upgrade the official kernel. You will find the script <a href="http://www.g-loaded.eu/2005/12/15/get-my-kernel-headers-script/" title="Link to the script's page">here</a>.</p>
<p>If you use the official Fedora kernel, I <strong>highly recommend</strong> that you use the respective <code>kernel-devel</code> RPM package in order to build any third party modules. If they fail due to missing headers, then use the kernel sources. I always consider the latter as a secondary option.</p>
<p>Unfortunately, my technical knowledge cannot give you any guarantees that this will work for you or if this guide is complete. At least, I do not have any issues when I compile and use kernel modules, which would not compile using the <code>kernel-devel</code> package due to missing headers. You are encouraged to leave your feedback.</p>
<h4>Further Reading</h4>
<p>You should read:</p>
<ul>
<li><a href="http://fedora.redhat.com/docs/release-notes/fc4/errata/" title="Link the Release Notes">The Fedora Core 4 Release Notes</a></li>
</ul>
<div class="cc-block"><em><a href="http://www.g-loaded.eu/2005/12/14/the-complete-fedora-kernel-headers/">The Complete Fedora Kernel Headers</a></em>, unless otherwise expressly stated, is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>. Terms and conditions beyond the scope of this license may be available at <a href="http://www.g-loaded.eu/about/disclaimer-and-license/">www.g-loaded.eu</a>.</div>
<h4>Related Articles</h4>
<ul><li><a href="http://www.g-loaded.eu/2005/12/15/get-my-kernel-headers-script/" rel="bookmark">Get my kernel headers script</a></li>
<li><a href="http://www.g-loaded.eu/2005/12/20/build-a-single-native-kernel-module/" rel="bookmark">Build a single native kernel module</a></li>
<li><a href="http://www.g-loaded.eu/2006/09/09/kernel-2617-and-lirc_gpio-driver/" rel="bookmark">Kernel 2.6.17 and lirc_gpio driver</a></li>
<li><a href="http://www.g-loaded.eu/2011/03/02/rhel-kernel-source-released-with-patches-already-applied/" rel="bookmark">RHEL kernel source released with patches already applied</a></li>
<li><a href="http://www.g-loaded.eu/2008/05/12/how-to-disable-ipv6-in-fedora-and-centos/" rel="bookmark">How to Disable IPv6 in Fedora and CentOS</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.g-loaded.eu/2005/12/14/the-complete-fedora-kernel-headers/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
	</channel>
</rss>

