CentOS 6.4 在默认情况下,没有指定源代码仓库。
如果想方便地下载 CentOS 6.4 的内核源代码,可按如下操作进行。
1. 进入仓库的目录 cd /etc/yum.repos.d/
2. 创建源代码仓库文件 touch CentOS-Source.repo
3. 将如下内容复制到 CentOS-Source.repo 中
[base-source]
name=CentOS-$releasever - Base Source
baseurl=http://vault.centos.org/6.4/os/Source/
enabled=1
[updates-source]
name=CentOS-$releasever - Updates Source
baseurl=http://vault.centos.org/6.4/updates/Source/
enabled=1
[extras-source]
name=CentOS-$releasever - Extras Source
baseurl=http://vault.centos.org/6.4/extras/Source/
enabled=1
[centosplus-source]
name=CentOS-$releasever - Plus Source
baseurl=http://vault.centos.org/6.4/centosplus/Source/
enabled=1
4. 更新 yum 缓存。
yum clean all
yum makecache
5. 这样完成了源代码仓库的添加和启用操作
运行命令:
#yumdownloader --source kernel.x86_64
下载源代码的rpm包到当前目录
6. create the ‘mockbuild’ user
# useradd -s /sbin/nologin mockbuild
7. 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:http://www.owlriver.com/tips/non-root/)
8.To install the source package and tools for CentOS 6:
As root, install the rpm-build, redhat-rpm-config, asciidoc, hmaccalc, perl-ExtUtils-Embed, xmlto, binutils-devel, elfutils-libelf-devel, newt-devel, python-devel and zlib-devel patchutils bison packages:
[root@host]# yum install rpm-build redhat-rpm-config asciidoc hmaccalc perl-ExtUtils-Embed xmlto
[root@host]# yum install binutils-devel elfutils-libelf-devel newt-devel python-devel zlib-devel patchutils bison
9.安装rpm packet
rpm -ivh kernel-2.6.32-358.2.1.e16.src.rpm
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.