Tuesday 1 February 2011

Installing Kernel Source Code in Red Hat/Centos Linux

If we want to install the full kernel source tree,

As root, install the packages rpm-build, redhat-rpm-config unifdef


[root@host]# yum install rpm-build redhat-rpm-config unifdef

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


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

packages must not be built using root account

find the kernel source rpm in the repos and download the SRPM  and install the srpm


[user@host]$ rpm -i http://mirror.centos.org/centos/5/updates/SRPMS/kernel-2.6.18-194.32.1.el5.src.rpm 2>&1 | grep -v mockb

Now that the source rpm is installed, unpack and prepare the source files:


[user@host]$ cd ~/rpmbuild/SPECS
[user@host SPECS]$ rpmbuild -bp --target=`uname -m` kernel-2.6.spec 2> prep-err.log | tee prep-out.log

The value of  `uname -m` sets --target to the architecture of your current kernel.

The kernel source tree will now be found in the directory ~/rpmbuild/BUILD/

Using the above procedure we can install source for all the rpms.

References:


1) http://wiki.centos.org/HowTos/I_need_the_Kernel_Source

2) Build Custom Kernel http://wiki.centos.org/HowTos/Custom_Kernel

3) Build custom kernel modules http://wiki.centos.org/HowTos/BuildingKernelModules

4) RHEL 6 source rpms: http://ftp.redhat.com/pub/redhat/linux/enterprise/6Server/en/os/SRPMS/

5) Kernel Howto : http://www.faqs.org/docs/Linux-HOWTO/Kernel-HOWTO.html#AEN307

6) Kernel development guidance : http://jehurst.wordpress.com/2011/01/13/rhel-for-the-clueless-rpm/
                                                      http://www.osdever.net/tutorials/view/brans-kernel-development-tutorial






No comments:

Post a Comment