RHEL 6: Compile stock-kernel
Posted: Thu Feb 20, 2014 9:24 pm
NOTE: This is work in progress and not finished. Might even be complete nonsense, but I keep my notes here until I've completed this task.
I've compiled a kernel hundreds of times already in the past, but this time, it's not just the kernel, but building proper packages. It's a bit trickier.
I want to do it clean, and stick to the RHEL-way-of-doing-it as good as possible. Unfortunately, I couldn't find proper documentation about re-compiling the stock kernel (not plain-vanilla source) in any Redhat articles. I guess it's due to support reasons.
The information I found is for Fedora or CentOS, but seems to work fine.
Here are 2 good sources for getting started: *) Install build-dependencies:
Some of the packages required for building the kernel are not in the default RHEL repositories. You must enable the "rhel-6-server-optional-beta-rpms" in "/etc/yum.repos.d/redhat.repo".
Search for a block like this:
By default, it will have "enabled = 0". Change this to "enabled = 1".
Then run:
Which should find and install the required packages for building your kernel.
*) Prepare kernel build:
The build process generated gpg keys for signing kernel modules. Install "rng-tools", to feed the random number generator with enough entropy.
Then use "rngd" to feed /dev/urandom:
If you don't do this, your rpmbuild will sit and wait for hours while generating the keys.
*) Rpmbuild kernel:
This builds only the base kernel (no xen, etc) without debuginfo:
You also have to compile again for "noarch", because otherwise you will run into the following dependency error when trying to install:
When the build process finished successfully, you will find the generated RPMs in "$HOME/rpmbuild/RPMS/", under their folders named after the built kernel package's architecture.
In my case (64bits), for example, the following files were created:
noarch:
*) Install the kernel:
Since the RPMs outside of a repository cannot install depending packages themselves, you must install the "kernel-firmware" manually before:
(Replace "<version>" with your kernel version name, and "<arch>" with your CPU architecture, such as "x86_64" for example)
In my case, the installation looked like this:
Links:
I've compiled a kernel hundreds of times already in the past, but this time, it's not just the kernel, but building proper packages. It's a bit trickier.
I want to do it clean, and stick to the RHEL-way-of-doing-it as good as possible. Unfortunately, I couldn't find proper documentation about re-compiling the stock kernel (not plain-vanilla source) in any Redhat articles. I guess it's due to support reasons.
The information I found is for Fedora or CentOS, but seems to work fine.
Here are 2 good sources for getting started: *) Install build-dependencies:
Some of the packages required for building the kernel are not in the default RHEL repositories. You must enable the "rhel-6-server-optional-beta-rpms" in "/etc/yum.repos.d/redhat.repo".
Search for a block like this:
Code: Select all
[rhel-6-server-optional-beta-rpms]
name = Red Hat Enterprise Linux 6 Server - Optional Beta (RPMs)
baseurl = https://cdn.redhat.com/content/beta/rhel/server/6/$releasever/$basearch/optional/os
enabled = 1
gpgcheck = 1
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-beta,file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
sslverify = 1
sslcacert = /etc/rhsm/ca/redhat-uep.pem
sslclientkey = /etc/pki/entitlement/4207967858922431493-key.pem
sslclientcert = /etc/pki/entitlement/4207967858922431493.pem
metadata_expire = 86400
ui_repoid_vars = releasever basearch
Then run:
Code: Select all
$ sudo yum-builddep kernel
*) Prepare kernel build:
The build process generated gpg keys for signing kernel modules. Install "rng-tools", to feed the random number generator with enough entropy.
Then use "rngd" to feed /dev/urandom:
Code: Select all
$ sudo rngd -r /dev/urandom
*) Rpmbuild kernel:
This builds only the base kernel (no xen, etc) without debuginfo:
Code: Select all
$ rpmbuild -bb --target=`uname -m` kernel.spec
In order to avoid this, build "noarch" too, so the "kernel-firmware" package is also built:error: Failed dependencies:
kernel-firmware >= 2.6.32-431.5.1.el6.sil3826 is needed by kernel-2.6.32-431.5.1.el6.sil3826.x86_64
Code: Select all
$ rpmbuild -bb --target=noarch kernel.spec
In my case (64bits), for example, the following files were created:
noarch:
.:
noarch
x86_64
./noarch:
kernel-abi-whitelists-2.6.32-431.5.1.el6.sil3826.noarch.rpm
kernel-doc-2.6.32-431.5.1.el6.sil3826.noarch.rpm
kernel-firmware-2.6.32-431.5.1.el6.sil3826.noarch.rpm
./x86_64:
kernel-2.6.32-431.5.1.el6.sil3826.x86_64.rpm
kernel-debug-2.6.32-431.5.1.el6.sil3826.x86_64.rpm
kernel-debug-debuginfo-2.6.32-431.5.1.el6.sil3826.x86_64.rpm
kernel-debug-devel-2.6.32-431.5.1.el6.sil3826.x86_64.rpm
kernel-debuginfo-2.6.32-431.5.1.el6.sil3826.x86_64.rpm
kernel-debuginfo-common-x86_64-2.6.32-431.5.1.el6.sil3826.x86_64.rpm
kernel-devel-2.6.32-431.5.1.el6.sil3826.x86_64.rpm
kernel-headers-2.6.32-431.5.1.el6.sil3826.x86_64.rpm
perf-2.6.32-431.5.1.el6.sil3826.x86_64.rpm
perf-debuginfo-2.6.32-431.5.1.el6.sil3826.x86_64.rpm
python-perf-2.6.32-431.5.1.el6.sil3826.x86_64.rpm
python-perf-debuginfo-2.6.32-431.5.1.el6.sil3826.x86_64.rpm
*) Install the kernel:
Since the RPMs outside of a repository cannot install depending packages themselves, you must install the "kernel-firmware" manually before:
Code: Select all
$ sudo rpm -ivh $HOME/rpmbuild/RPMS/noarch/kernel-<version>.<arch>.rpm
$ sudo rpm -ivh $HOME/rpmbuild/RPMS/<arch>/kernel-<version>.<arch>.rpm
In my case, the installation looked like this:
Code: Select all
[pb@bb2 RPMS]$ sudo rpm -ivh noarch/kernel-firmware-2.6.32-431.5.1.el6.sil3826.noarch.rpm
Preparing... ########################################### [100%]
1:kernel-firmware ########################################### [100%]
[pb@bb2 RPMS]$ sudo rpm -ivh x86_64/kernel-2.6.32-431.5.1.el6.sil3826.x86_64.rpm
Preparing... ########################################### [100%]
1:kernel ########################################### [100%]