centos下安装内核源码包
2013-12-21 14:09:06 阿炯

一些系统级的应用软件在安装时需要用到内核源码,但并不是所有的系统中安装了对应的内核包。像centos6上一般就只需要有kernel-devel包安装了即可:
yum install kernel-devel

如果安装好后仍不能解决问题,那就需要看下面的内容了。

On CentOS 6 there is only one kernel-devel package for both architectures x86_64 and i386 however on CentOS 5 there are three versions, if you are unsure on what version you should install then run the command uname -r which will display your kernel version you then need to match the kernel version you are running with the correct kernel-devel package below:

CentOS 5 install kernel-devel for i386 & x86_64:
yum install kernel-devel

Centos 5 install Xen kernel-devel for x86_64 & i386:
yum install kernel-xen-devel

And finally to install kerenl-devel for PAE:
yum install kernel-pae-devel

下面的方法适用于centos 5及6
CentOS Kernel source install (full) for CentOS 5 & 6

如果只是想用包来安装,解决软件对其的依赖而已,可用如下指令:

yum -y install dkms gcc kernel-headers-`uname -r` kernel-devel-`uname -r` kernel-`uname -r`

If install kernel-devel above does not work or you require the full CentOS kernel source for another reason you can install it on CentOS 5 & 6 with:
yum install rpm-build redhat-rpm-config unifdef

如果是非root用户:
mkdir -p ~/rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}
echo '%_topdir %(echo $HOME)/rpmbuild' > ~/.rpmmacros

安装centos 6的内核源码
To install the CentOS 6 kernel source

The following command will install the kernel source for CentOS 6.2, you can install it for other version of CentOS 6 simply by using the URL for the alternative version.

rpm -i http://vault.centos.org/6.2/updates/Source/SPackages/kernel-2.6.32-220.7.1.el6.src.rpm 2>&1 | grep -v mockb

安装centos 5.x的内核源码
How To install the CentOS 5.x kernel source

The following will install the full kernel source on CentOS 5.8, again the same applies – you can install the kernel source for another version of CentOS 5 by swapping the URL.

rpm -i http://vault.centos.org/5.8/updates/SRPMS/kernel-2.6.18-308.1.1.el5.src.rpm 2>&1 | grep -v mockb

当安装好了对应的内核包,进行如下的操作:
cd ~/rpmbuild/SPECS

And then unpack the kernel source with:
rpmbuild -bp --target=`uname -m` kernel-2.6.spec 2> prep-err.log | tee prep-out.log

Make sure you copy and paste the commands above as the uname -m command will pull your kernel arch (e.g x86_64) and prep the source for your kernel, you can find the kernel source in your home dir in a directory called rpmbuild/BUILD/ to access the CentOS kernel source install dir type the following as the logged in user you built the kernel source with ~/rpmbuild/BUILD/