这是原文:https://www.jianshu.com/p/482d5d68f81f
作者:骆的沙
来源:简书
以防原文消失,特地在此记录。
这个操作是可行的,照着做可以成功编译出 rpm 包。
步骤如下:
下载 linux kernel 4.14 包(以 4.14 为例)
从 https://mirrors.edge.kernel.org/pub/linux/kernel 中找到 4.14.124 并下载
[root@aws-172-20-20-101 kernel]# wget https://mirrors.edge.kernel.org/pub/linux/kernel/v4.x/linux-4.14.124.tar.gz
安装一些编译内核的依赖:
[root@aws-172-20-20-101 kernel]# yum install -y ncurses-devel elfutils-libelf-devel openssl-devel bc
安装 rpm 编译到依赖
[root@aws-172-20-20-101 kernel]# yum install -y gcc rpm-build rpm-devel rpmlint make python bash coreutils diffutils patch rpmdevtools
解压 kernel 4.14 包
[root@aws-172-20-20-101 kernel]# tar -zxvf linux-4.14.124.tar.gz
选择配置项,自定义内核编译:
原文:[root@aws-172-20-20-101 kernel]# make menuconfig
【注意】这里实际上是在 linux-kernel_name 目录下编译:
编译内核并生成 rpm 包
make rpm 执行会自动生成 *.spec 文件,编译完后会自动生成 rmp 安装包,编译时间比较长,建议使用配置较大的机器进行编译(4C16G的机器亲测30分钟内可编译完,1C1G一天都够呛),磁盘空间要保持在20G以上
[root@aws-172-20-20-101 kernel]# make rpm &
[root@aws-172-20-20-101 kernel]# make rpm-pkg &
编译好后的 rmp 包路径会有提示
[root@aws-172-20-20-101 kernel]# cd /root/rpmbuild/RPMS/uname -m
/
[root@aws-172-20-20-101 kernel]# tree RPMS/
RPMS/
└── i386
├── kernel-4.14.124.x86_64.rpm
├── kernel-devel-4.14.124.x86_64.rpm
└── kernel-headers-4.14.124.x86_64.rpm
安装新编译好的内核
编译好后的 rpm 即可随处使用了
[root@aws-172-20-20-101 kernel]# rpm -Uvh kernel--.rpm
安装完成后设置 4.14 位默认启动项
[root@aws-172-20-20-101 kernel]# cat /boot/grub2/grub.cfg |grep menuentry
if [ x"${feature_menuentry_id}" = xy ]; then
menuentry_id_option="--id"
menuentry_id_option=""
export menuentry_id_option
menuentry 'CentOS Linux (4.14.124.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-862.3.2.el7.x86_64-advanced-8c1540fa-e2b4-407d-bcd1-59848a73e463' {
menuentry 'CentOS Linux (3.10.0-957.12.2.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-862.3.2.el7.x86_64-advanced-8c1540fa-e2b4-407d-bcd1-59848a73e463' {
menuentry 'CentOS Linux (3.10.0-862.3.2.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-862.3.2.el7.x86_64-advanced-8c1540fa-e2b4-407d-bcd1-59848a73e463' {
menuentry 'CentOS Linux (0-rescue-b30d0f2110ac3807b210c19ede3ce88f) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-0-rescue-b30d0f2110ac3807b210c19ede3ce88f-advanced-8c1540fa-e2b4-407d-bcd1-59848a73e463’ {
设置默认启动
[root@aws-172-20-20-101 kernel]# grub2-set-default 'CentOS Linux (4.14.124.x86_64) 7 (Core)’
验证
[root@aws-172-20-20-101 kernel]# grub2-editenv list
saved_entry=CentOS Linux (4.14.124.x86_64) 7 (Core)
重启机器
[root@aws-172-20-20-101 kernel]# reboot
[root@aws-172-20-20-101 kernel]# uname -r