Вы находитесь на странице: 1из 3

How to build a custom kernel?

ISSUE

Even though Red Hat does not provide any support for the customized kernel, as a user, you want to rebuild a kernel (e.g. to test a change or

apply a local fix until errata are released).


When you recompile the kernel, the size of each binary is a lot bigger than the one Red Hat provides. How can the binaries' size be reduced to
sizes similar to those in the Red Hat shipped kernel binary RPM?

ENVIRONMENT

Red Hat Enterprise Linux 4

Red Hat Enterprise Linux 5


Red Hat Enterprise Linux 6

RESOLUTION
To build a custom kernel, you need to download the source rpm first. The kernel-version.src.rpmcan be downloaded from the Red Hat Customer Portal.
The steps to rebuild the kernel are described below.
1) Install source rpm and apply the Red Hat patches to the original kernel source
# rpm -ivh kernel-2.6.x-x.src.rpm
# cd /usr/src/redhat/SPECS
# rpmbuild -bp --target=*i686* kernel.spec

These commands will set up the kernel source in the /usr/src/redhat/BUILD/ directory.
2) Move to the directory to rebuild kernel:
# cd /usr/src/redhat/BUILD/kernel-*2.6.x*/linux-*2.6.x*

3) Build the kernel:


# make bzImage ; make modules ; make install; make modules_install

This will compile modules and bootable kernel image.


If the build succeeds, it will install the modules into /lib/modules/2.6.x../ directory and install the kernel image into /boot directory together with some
related files.
However, this process is not devoid of problems. if the user has limited resources for their file system because the kernel built with those commands create
much bigger files compared to the Red Hat's files. It happens because Red Hat's kernel is stripped of some unnecessary information.
Alternative way for Step 3 :
4) Build a kernel with INSTALL_MOD_STRIP option turned on:
# make bzImage && make modules && make INSTALL_MOD_STRIP=1 install && make INSTALL_MOD_STRIP=1 modules_install

5) In Red Hat Enterprise Linux 4, the kernel Makefile doesn't have this
INSTALL_MOD_STRIP option, so those commands cannot be used. The spec file in Red Hat Enterprise Linux 4 uses different approach. The following is a
snippet from the kernel-2.6.spec file:
# set the EXTRAVERSION to <version>custom, so that people who follow a kernel building howto
# don't accidentally overwrite their currently working moduleset and hose
# their system
perl -p -i -e "s/^EXTRAVERSION.*/EXTRAVERSION = -%{release}custom/" $RPM_BUILD_ROOT/usr/src/linux-%{KVERREL}/Makefile
# some config options may be appropriate for an rpm kernel build but are less so for custom user builds,
# change those to values that are more appropriate as default for people who build their own kernel.
perl -p -i -e "s/^CONFIG_DEBUG_INFO.*/# CONFIG_DEBUG_INFO is not set/" $RPM_BUILD_ROOT/usr/src/linux-%{KVERREL}/configs/*
perl -p -i -e "s/^.*CONFIG_DEBUG_PAGEALLOC.*/# CONFIG_DEBUG_PAGEALLOC is not set/" $RPM_BUILD_ROOT/usr/src/linux -%{KVERREL}/c
onfigs/*
perl -p -i -e "s/^.*CONFIG_DEBUG_SLAB.*/# CONFIG_DEBUG_SLAB is not set/" $RPM_BUILD_ROOT/usr/src/linux-%{KVERREL}/configs/*
perl -p -i -e "s/^.*CONFIG_DEBUG_SPINLOCK.*/# CONFIG_DEBUG_SPINLOCK is not set/" $RPM_BUILD_ROOT/usr/src/linux-%{KVERREL}/con
figs/*

perl -p -i -e "s/^.*CONFIG_DEBUG_HIGHMEM.*/# CONFIG_DEBUG_HIGHMEM is not set/" $RPM_BUILD_ROOT/usr/src/linux-%{KVERREL}/confi


gs/*
perl -p -i -e "s/^.*CONFIG_MODULE_SIG.*/# CONFIG_MODULE_SIG is not set/" $RPM_BUILD_ROOT/usr/src/linux-%{KVERREL}/configs/*

In RHEL4, it doesn't use strip command. Instead it use compile options to remove debug information at the time of kernel compile. So, run the previous
commands before kernel compilation.
If these steps feel tedious, reuse the original rpm spec file.
For detailed information for this steps at the following link:http://fedoraproject.org/wiki/Building_a_custom_kernel.

Comments
Refer to https://access.redhat.com/support/offerings/production/soc.html for details on the Red Hat Global Support Services Production Support Scope of
Coverage and note that rebuilt RPMs are considered modified RPMs.
If you wish to see Red Hat make particular changes to the kernel, please open a support case with Red Hat Global Support Services and request that
these changes be considered for a feature request.

Вам также может понравиться