CentOS安装相应版本的内核源码

昨天接到同事给安排的新任务,测试系统性能;网上查了些资料,目测perf功能很强大,而且是内核源码自带的,编译安装即可使用;看了下自己的虚拟机,没有内核源码,好吧,装一个;

查看一下系统版本:

1 #cat /etc/redhat-release 
2 CentOS Linux release 7.5.1804 (Core)
3 
4 #uname -r
5 3.10.0-862.el7.x86_64

 

去CentOS官网找对应的内核源码包,下面地址,进去找到与版本信息对应的源码目录,找到内核源码包,下载即可:

#http://vault.centos.org/
#wget http://vault.centos.org/7.5.1804/os/Source/SPackages/kernel-3.10.0-862.el7.src.rpm

 

直接使用rpm安装的话,会提示一个错误:

#rpm -i kernel-3.10.0-862.el7.src.rpm
Warning: user mockbuild does not exist. using root
...

这时需要安装一个mock,并新建一个mockbuild用户:

#yum install mock
#useradd -s /sbin/nologin mockbuild

 

好了,继续安装:

#rpm -i kernel-3.10.0-862.el7.src.rpm

 

这时回到root根目录,会有一个rpmbuild目录,进去该目录下的SPEC

#cd ~/rpmbuild/SPECS

 

开始执行rpmbuild:

#rpmbuild -bp --target=$(uname -m) kernel.spec

这时应该会提示一堆错误信息,因为需要很多依赖包,安装之:

#yum install rpm-build redhat-rpm-config asciidoc hmaccalc perl-ExtUtils-Embed pesign xmlto
#yum install audit-libs-devel binutils-devel elfutils-devel elfutils-libelf-devel java-devel
#yum install ncurses-devel newt-devel numactl-devel pciutils-devel python-devel zlib-devel

再次执行rpmbuild命令,如果还提示有缺少,则对应安装即可;

 

接下来的过程很愉快:

#rpmbuild -bp --target=$(uname -m) kernel.spec
Building target platforms: x86_64
Building for target x86_64
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.eM2FKD
+ umask 022
+ cd /root/rpmbuild/BUILD
+ patch_command='patch -p1 -F1 -s'
+ cd /root/rpmbuild/BUILD
+ rm -rf kernel-3.10.0-862.el7
+ /usr/bin/mkdir -p kernel-3.10.0-862.el7
+ cd kernel-3.10.0-862.el7
+ /usr/bin/xz -dc /root/rpmbuild/SOURCES/linux-3.10.0-862.el7.tar.xz
+ /usr/bin/tar -xf -
+ STATUS=0
+ '[' 0 -ne 0 ']'
+ /usr/bin/chmod -Rf a+rX,u+w,g-w,o-w .
+ mv linux-3.10.0-862.el7 linux-3.10.0-862.el7.centos.x86_64
+ cd linux-3.10.0-862.el7.centos.x86_64
...
...

 

这时,就可以找到源码包了,在~/rpmbuild/BUILD目录下:

#cd ~/rpmbuild/BUILD/kernel-3.10.0-862.el7/linux-3.10.0-862.el7.centos.x86_64

 

参考:CentOS官方说明:

https://wiki.centos.org/zh/HowTos/I_need_the_Kernel_Source

 

posted @ 2019-10-30 22:35  AlexAlex  阅读(12024)  评论(0编辑  收藏  举报