Skip to content

通过知识获得解放,通过技术获得自由

Menu
  • 专题目录
  • 液压相关
    • 液压技术
    • 液压相邻技术
    • 液压应用
  • 计算机相关
    • 计算机和软件
    • 网络和网站技术
  • 哲学
  • 关于本站
Menu

centos8stream编译安装linux内核[0]

Posted on 2023年11月14日2025年5月6日 by

linux内核官网:https://www.kernel.org/

https://www.kernel.org/doc/html/latest/process/changes.html

https://www.kernel.org/doc/html/latest/translations/zh_CN/index.html

最小编译要求:

  • 来由

下过程部署linux4.9.204和linux5.10.60成功(都是长期版本),但是部署linux5.13.12不成功

在centos上部署的7,8次,在centos8stream上测试次数较多,在centos7上也测试过,目前linux4.9.204在两个版本上都能够编译成功。

一次编译在2-4h左右,根据机器的特性。

一般情况下无需自行编译linux内核,尤其是在大规模使用的linux发行版上,但是为了加深对于linux内核的理解,并减少不必要的内核的功能,或者尝试最新的内核的功能,才需要自行编译内核。

鉴于按照步骤交叉编译过openwrt的R2s,rpi4b,r4s的固件,因此想尝试直接编译能用的linux最新内核。

测试系统:centos8stream

  • 前置条件
yum install wget nano tar gcc gdb make flex bison openssl-devel elfutils-libelf-devel python3 bc ncurses-devel perl perl perl-devel gcc gcc-c++ -y
  • 编译过程
简单说明内核编译的步骤为何:
1. 先下载内核原始码,
2. 以下以 Tarball 来处理,解开原始码到 /usr/src/kernels 目彔下;
3. 先进行旧数据清除的动作:『make mrproper』;
4. 开始选择内核功能,可以利用『make menuconfig』、『make oldconfig』、『make gconfig』等等;
5. 清除过去的中间暂存盘资料:『make clean』
6. 开始内核档案不内核模块的编译:『make vmlinux』,『make bzImage』、『make modules』
7. 开始内核模块的安装:『make modules_install』
8. 开始内核档案的安装:『make install』;

详细过程如下:

1)检查当前内核

2)下载源码

cd /usr/src/kernels
wget https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.10.60.tar.xz
tar xvf linux-5.10.60.tar.xz
cd linux-5.10.60

3)清理

#先进行旧数据清除的动作,首次编译前需要处理,会清除config
make mrproper 

#清除过去的中间暂存盘资料,保留config
make clean

4)配置config

#cp /boot/config-4.18.0-326.el8.x86_64 /lnmp/linux-5.13.12/.config #不推荐
make menuconfig #可视化检查配置,无需修改,即无需新内核的新的特性

详细配置如下:

关闭虚拟化(vps中无需虚拟化)

模块的选择和模块验证问题

save后需要修改.config如下:

CONFIG_SYSTEM_TRUSTED_KEYS=""
CONFIG_SYSTEM_BLACKLIST_HASH_LIST=""

此处为坑:内核签名和模块安装的问题。

5)裸核和内核镜像的编译

make vmlinux -j 16 #Build the bare kernel
make bzImage -j 16 #Compressed kernel image

6)编译和安装模块(非常耗时)

#开始内核模块的安装 make modules -j 16 #Build all modules make modules_install

7)安装内核

#内核的安装
make install
reboot

8)启动测试

部署linux4.9.204和linux5.10.60成功,但是部署linux5.13.12不成功

启动显示故障如下:

  • 小结

前前后后部署了很多次,都没有成功,在Ubuntu和centos系统上来回切换的测试,都是不行,直到找到合适讲解linux内核编译的文章。linux内核的选项众多,彼此间有关联,既有硬件平台的关联性,也有软件间的关联,目前没有搞清楚具体的关系,也不清楚新的内核较老的内核有哪些更新和改进。

 

 

补充问题:

1)BTF问题的处理

BTF: .tmp_vmlinux.btf: pahole (pahole) is not available
Failed to generate BTF for vmlinux
Try to disable CONFIG_DEBUG_INFO_BTF
make: *** [Makefile:1205: vmlinux] Error 1

2)blowfish问题

3)/dev/disk/by-uuid/XXXX does not exist

新内核是进不去了,强行关机,重启,选择之前的内核进入系统。
查看/boot挂载的分区:

使用dracut生成该内核的启动文件

ls -l /dev/disk/by-uuid/

cp /lnmp/linux-5.13.12/arch/x86_64/boot/bzImage /boot/vmlinuz-5.13.12
dracut --kver 5.13.12 -k /lib/modules/5.13.12/ --kernel-cmdline root=UUID=6efb948d-7043-41ab-8532-2092c335e427 initramfs-5.13.12.img --force

 

参考资料:

  1. https://blog.51cto.com/u_13434656/2526526
  2. https://zhuanlan.zhihu.com/p/346001344
  3. https://zhuanlan.zhihu.com/p/164910411
  4. https://zhuanlan.zhihu.com/p/346001344
  5. https://blog.csdn.net/nnaiwa/article/details/81706448
  6. https://www.cxyzjd.com/article/u010096900/70339677
  7. https://blog.51cto.com/mengzhaofu/1854093
  8. https://blog.csdn.net/u012325865/article/details/102905024
  9. https://www.jianshu.com/p/fdf6bb6c5b9c
  10. https://www.linuxidc.com/Linux/2019-11/161257.htm
  11. 鸟哥的linux私房菜

欢迎回来

希望本站对你有所帮助!

如有疑问请联系info@fanlog.org
2023 年 11 月
一二三四五六日
 12345
6789101112
13141516171819
20212223242526
27282930 
« 6 月    

AI辅助 (17)

© 2025 | Powered by Superbs Personal Blog theme
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept All”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent.
Cookie SettingsAccept All
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT