Differences between revisions 329 and 330

Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
#acl ZachVargas:read,write,revert Default

I Need the Kernel Source

Created by JohnnyHughes. Currently maintained by AlanBartlett and AkemiYagi.

1. Maybe you do not need the full kernel source

If you need to compile a kernel driver (module), the chances are you do not really need to install the full kernel source tree. You might just need to install the kernel-devel package. (If, however, you are certain that the full source tree is required, please follow the instructions in Section 2.)

In CentOS-7, there is just one kernel-devel package available:

  • kernel-devel (64-bit architecture)

(Note that CentOS-7 32-bit is available through the AltArch i386 SIG.)

In CentOS-6, there is just one kernel-devel package available:

  • kernel-devel (both 32- & 64-bit architectures)

You can install the kernel-devel package by:

[root@host]# yum install kernel-devel

If your kernel is not listed by yum because it is in an older tree, you can download it manually from the CentOS Vault.

CentOS-7: Look in either the 7.N.YYMM/os/x86_64/Packages/ or the 7.N.YYMM/updates/x86_64/Packages/ directories for the kernel-devel-version.x86_64.rpm

CentOS-6: Look in either the 6.N/os/arch/Packages/ or the 6.N/updates/arch/Packages/ directories for the kernel-devel-version.arch.rpm

Once you have the proper kernel[-type]-devel-version.arch.rpm package installed, try to compile your module. It should work that way. If it does not, please provide feedback to the module's developer as this is the way all new kernel modules should be designed to be built.

2. If you really need the full kernel source

If you really must have the kernel source tree, for whatever reason, it is obtainable.

As an ordinary user, not root, create a build tree based on a ~/rpmbuild/ directory:

[user@host]$ mkdir -p ~/rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}
[user@host]$ echo '%_topdir %(echo $HOME)/rpmbuild' > ~/.rpmmacros

<!> You are strongly advised against package building as root. (See: Building Source RPM as non-root under CentOS)


To install the source package and tools for CentOS-7:

As root install the asciidoc, audit-libs-devel, bash, bc, binutils, binutils-devel, bison, diffutils, elfutils, elfutils-devel, findutils, flex, gawk, gcc, gettext, gzip, hmaccalc, hostname, java-devel, m4, make, module-init-tools, ncurses-devel, net-tools, newt-devel, numactl-devel, openssl, patch, pciutils-devel, perl, perl-ExtUtils-Embed, pesign, python-devel, redhat-rpm-config, rpm-build, sh-utils, tar, xmlto, xz and zlib-devel packages:

[root@host]# yum install asciidoc audit-libs-devel bash bc binutils binutils-devel bison diffutils elfutils
[root@host]# yum install elfutils-devel findutils flex gawk gcc gettext gzip hmaccalc hostname java-devel
[root@host]# yum install m4 make module-init-tools ncurses-devel net-tools newt-devel numactl-devel openssl
[root@host]# yum install patch pciutils-devel perl perl-ExtUtils-Embed pesign python-devel redhat-rpm-config
[root@host]# yum install rpm-build sh-utils tar xmlto xz zlib-devel

Find the kernel source rpm package in:

(Replace the "N.YYMM" with the relevant sub-version, year and month numbers.)

As an ordinary user, not root, install the source package by executing:

[user@host]$ rpm -i http://vault.centos.org/7.6.1810/os/Source/SPackages/kernel-3.10.0-957.el7.src.rpm 2>&1 | grep -v exist


To install the source package and tools for CentOS-6:

As root install the asciidoc, audit-libs-devel, bash, binutils, binutils-devel, bison, bzip2, diffutils, elfutils-devel, elfutils-libelf-devel, findutils, flex, gawk, gcc, gnupg, gzip, hmaccalc, m4, make, module-init-tools, net-tools, newt-devel, patch, patchutils, perl, perl-ExtUtils-Embed, python, python-devel, redhat-rpm-config, rpm-build, sh-utils, tar, xmlto and zlib-devel packages:

[root@host]# yum install asciidoc audit-libs-devel bash binutils binutils-devel bison bzip2 diffutils elfutils-devel
[root@host]# yum install elfutils-libelf-devel findutils flex gawk gcc gnupg gzip hmaccalc m4 make module-init-tools
[root@host]# yum install net-tools newt-devel patch patchutils perl perl-ExtUtils-Embed python python-devel
[root@host]# yum install redhat-rpm-config rpm-build sh-utils tar xmlto zlib-devel

Find the kernel source rpm package in:

(Replace the "N" with the relevant sub-version number.)

As an ordinary user, not root, install the source package by executing:

[user@host]$ rpm -i http://vault.centos.org/6.10/updates/Source/SPackages/kernel-2.6.32-754.9.1.el6.src.rpm 2>&1 | grep -v exist


Now that the source package and tools are installed, unpack and prepare the source files:

[user@host]$ cd ~/rpmbuild/SPECS
[user@host SPECS]$ rpmbuild -bp --target=$(uname -m) kernel.spec

The value of $(uname -m) sets the target to the architecture of your current kernel. This is generally accepted, as most people will need either i686 or x86_64 as the target.

The kernel source tree will now be found under the ~/rpmbuild/BUILD/kernel*/linux*/ directory.

HowTos/I need the Kernel Source (last edited 2018-12-08 22:24:20 by AlanBartlett)