通过源码的方式替换
获取内核源码的路径:https://www.kernel.org/pub/linux/kernel/
解压内核源码到路径/usr/src/kernels/
Make mrproper的作用是在每次配置并重新编译内核前执行该命令。将会清理源代码树,包括过去曾经配置的内核配置文件“.config”都将被清除。以免影响新的内核编译。
make menuconfig命令用于生成的内核配置文件
内核配置的方式分为如下几种,选择其中一种即可:
#make menuconfig //基于ncurse库编制的图形工具界面
#make config //基于文本命令行工具,不推荐使用
#make xconfig //基于X11图形工具界面
#make gconfig //基于gtk+的图形工具界面
采用make menuconfig 时出现图形界面的含义如下:
对每一个配置选项,用户有三种选择,它们分别代表的含义如下:
<*>或[*]——将该功能编译进内核
[ ]——不将该功能编译进内核
[M]——将该功能编译成可以在需要时动态插入到内核中的代码
最后要执行save(版本不同可能执行方式不同,3.10.40会有save选项,而2.6.33则是有一个选项:save an alternate configuration file),这样就生成了配置好的.config。
开始编译内核源码,通过make将生成内核模块和vmlinuz,initrd.img,Symtem.map文件
注:#make相当于分别执行#makebzImage 和#make modules。根据需要也可以分开执行
安装模块:编译成功后,系统会在/lib/modules目录下生成一个****(版本号)子目录,里面存放着新内核的所有可加载模块(即将编译好的modules拷贝到/lib/modules下)
安装内核,该命令会复制.config,vmlinuz,initrd.img,System.map文件到/boot目录、更新grub。
通过更改default的值,来执行内核的默认启动版本。如图,如果default=0,则系统默认启动的内核版本为2.6.31.1
重启设备之后,通过命令uname –a 、 uname -r查看系统内核版本。
//http://vault.centos.org/6.5/centosplus/Source/SPackages/
源代码的官网:http://vault.centos.org/
进入官网后,再一次进入6.7/,进入os/,进入Source/,进入SPackages/,找到kernel-2.6.32-573.el6.src.rpm下载就行了
我使用的是kernel-2.6.32-431.el6.centos.plus.src.rpm
rpm -i kernel-2.6.32-431.el6.centos.plus.src.rpm
该步骤结束之后会生成/root/rpmbuild/SPECS/kernel.spec
可能会遇到如下问题:
rpm -ivhkernel-2.6.32-431.el6.centos.plus.src.rpm
1:kernel warning: user mockbuild doesnot exist - using root
warning:group mockbuild does not exist - using root
warning:user mockbuild does not exist - using root
warning:group mockbuild does not exist - using root
warning:user mockbuild does not exist - using root
warning:group mockbuild does not exist - using root
warning:user mockbuild does not exist - using root
warning:group mockbuild does not exist - using root
warning:user mockbuild does not exist - using root
warning:group mockbuild does not exist - using root
warning:user mockbuild does not exist - using root
warning:group mockbuild does not exist - using root
warning:user mockbuild does not exist - using root
warning:group mockbuild does not exist - using root
warning:user mockbuild does not exist - using root
warning:group mockbuild does not exist - using root
warning:user mockbuild does not exist - using root
warning:group mockbuild does not exist - using root
warning:user mockbuild does not exist - using root
warning:group mockbuild does not exist - using root
warning:user mockbuild does not exist - using root
warning:group mockbuild does not exist - using root
warning:user mockbuild does not exist - using root
warning:group mockbuild does not exist - using root
warning:user mockbuild does not exist - using root
warning:group mockbuild does not exist - using root
warning:user mockbuild does not exist - using root
warning:group mockbuild does not exist - using root
warning:user mockbuild does not exist - using root
warning:group mockbuild does not exist - using root
warning:user mockbuild does not exist - using root
warning:group mockbuild does not exist - using root
warning:user mockbuild does not exist - using root
warning:group mockbuild does not exist - using root
warning:user mockbuild does not exist - using root
warning:group mockbuild does not exist - using root
warning:user mockbuild does not exist - using root
warning:group mockbuild does not exist - using root
warning:user mockbuild does not exist - using root
warning:group mockbuild does not exist - using root
warning:user mockbuild does not exist - using root
warning:group mockbuild does not exist - using root
warning:user mockbuild does not exist - using root
warning:group mockbuild does not exist - using root
warning:user mockbuild does not exist - using root
warning:group mockbuild does not exist - using root
warning:user mockbuild does not exist - using root
warning:group mockbuild does not exist - using root
warning:user mockbuild does not exist - using root
warning:group mockbuild does not exist - using root
###########################################[100%]
warning:user mockbuild does not exist - using root
warning:group mockbuild does not exist - using root
warning:user mockbuild does not exist - using root
warning:group mockbuild does not exist - using root
warning:user mockbuild does not exist - using root
warning:group mockbuild does not exist - using root
warning:user mockbuild does not exist - using root
warning: group mockbuild does not exist - using root
解决方式:添加用户和组后,再重新执行上述步骤
groupaddmockbuild
useradd mockbuild-g mockbuild
执行命令:rpmbuild -bb kernel.spec
可能会遇到如下问题:
[root@ServerSPECS]# rpmbuild -bb kernel.spec
error:Failed build dependencies:
redhat-rpm-config is needed bykernel-2.6.32-431.el6.centos.plus.x86_64
patchutils is needed bykernel-2.6.32-431.el6.centos.plus.x86_64
xmlto is needed bykernel-2.6.32-431.el6.centos.plus.x86_64
asciidoc is needed bykernel-2.6.32-431.el6.centos.plus.x86_64
binutils-devel is needed bykernel-2.6.32-431.el6.centos.plus.x86_64
newt-devel is needed bykernel-2.6.32-431.el6.centos.plus.x86_64
audit-libs-devel is needed bykernel-2.6.32-431.el6.centos.plus.x86_64
perl(ExtUtils::Embed) is needed bykernel-2.6.32-431.el6.centos.plus.x86_64
bison is needed bykernel-2.6.32-431.el6.centos.plus.x86_64
flex is needed bykernel-2.6.32-431.el6.centos.plus.x86_64
hmaccalc is needed bykernel-2.6.32-431.el6.centos.plus.x86_64
解决方式:
说明依赖的包没有安装,需要将下边的包安装上。
bison-2.4.1-5.el6.x86_64.rpm perl-ExtUtils-Embed-1.28-141.el6_7.1.x86_64.rpm
flex-2.5.35-9.el6.x86_64.rpm redhat-rpm-config-9.0.3-51.el6.centos.noarch.rpm
asciidoc-8.4.5-4.1.el6.noarch.rpm
hmaccalc-0.9.12-2.el6.x86_64.rpm
slang-devel-2.2.1-1.el6.x86_64.rpm
audit-libs-devel-2.4.5-3.el6.x86_64.rpm newt-devel-0.52.11-3.el6.x86_64.rpm
xmlto-0.0.23-3.el6.x86_64.rpm
binutils-devel-2.20.51.0.2-5.44.el6.x86_64.rpm
patchutils-0.3.1-3.1.el6.x86_64.rpm
安装这些包的过程中,可能会依赖其他包,如下:
audit-libs-2.4.5-3.el6.x86_64.rpm
lynx-2.8.6-27.el6.x86_64.rpm
perl-libs-5.10.1-141.el6_7.1.x86_64.rpm
centos-indexhtml-6-2.el6.centos.noarch.rpm
perl-5.10.1-141.el6_7.1.x86_64.rpm
安装过程中可能会遇到如下问题:
[root@Server 1]# rpm -ivhperl-5.10.1-141.el6_7.1.x86_64.rpm
error:Failed dependencies:
perl-libs = 4:5.10.1-141.el6_7.1 is needed byperl-4:5.10.1-141.el6_7.1.x86_64
[root@Server1]# rpm -ivh perl-libs-5.10.1-141.el6_7.1.x86_64.rpm
error:Failed dependencies:
perl = 4:5.10.1-141.el6_7.1 is needed byperl-libs-4:5.10.1-141.el6_7.1.x86_64
解决方式:
这是因为安装perl时二者相互依赖,且与之前的包有冲突。可以通过如下方式:
rpm -ivh perl-libs-5.10.1-141.el6_7.1.x86_64.rpmperl-5.10.1-141.el6_7.1.x86_64.rpm --force
安装完以上依赖包后,重新执行rpmbuild -bb kernel.spec命令时,可能会出现如下问题:
卡住gpg:keyring `./pubring.gpg' created不动了
解决方式:
执行一下命令:rngd -r /dev/urandom
但是rng这个工具在我们的icfs系统中已经被裁减(原版的ceotos上存在该命令,已验证),因此需要手动安装上。步骤如下:
rpm -ivhrng-tools-5-2.el6_7.x86_64.rpm
到此,结束以上所有步骤之后,会在以下目录中生成内核源码:
/root/rpmbuild/BUILD/kernel-2.6.32-431.el6/linux-2.6.32-431.el6.centos.plus.x86_64
进入生成的源码目录:
cd /root/rpmbuild/BUILD/kernel-2.6.32-431.el6/linux-2.6.32-431.el6.centos.plus.x86_64
cp /boot/config-2.6.32-431.el6.x86_64 .config
或者cp/usr/src/kernels/2.6.32-431.el6.x86_64/.config .config
Make –j24
说明:在方式二中,在源码init/main.c中添加了打印信息,在内核启动后能够在/var/log/messages中找到。
风险事项:
1. 安装包时有冲突项。
2.
网友评论