由于工作需要调试内核,加点打印,本文讲述如何编译了一个自己的内核,并且安装
1 下载内核源码
repository:https://mirrors.tuna.tsinghua.edu.cn/git/linux-stable.git
branch:linux-6.11.y
2 打fedora的patch
repository:https://github.com/whitehara/kernel-patch-fedora
给内核源码打上对应版本的patch。否则启动后,有些内核模块安装不上:
.gnu.linkonce.this_module section size must match the kernel's built struct module size at run time
这个报错是内核头文件和内核选项不匹配。
3 然后开始编译:
$ cp /boot/config-6.11.4-301.fc41.x86_64 .config
$ make oldconfig
$ make bzImage -j12
$ make modules -j12
4 安装:
$ sudo make modules_install
$ sudo make install
将安装内核模块,内核,initramfs:
/lib/modules/6.11.8
/boot/vmlinuz-6.11.8
/boot/initramfs-6.11.8.img
5 将启动改成console模式,便于检查发现的问题,否则启动失败会卡在fedora的图形界面
编辑/etc/default/grub,将GRUB_CMDLINE_LINUX改成3
#GRUB_CMDLINE_LINUX="rhgb quiet"
GRUB_CMDLINE_LINUX="3"
然后生效:
$ sudo grub2-mkconfig -o /boot/grub2/grub.cfg
6 重启
$ uname -a
Linux fedora 6.11.8 #1 SMP PREEMPT_DYNAMIC TKG Mon Nov 18 13:02:04 CST 2024 x86_64 GNU/Linux
可以看到,内核版本变成了,我们编译的6.11.8
7 调试完毕后,删除启动条目
sudo rm /boot/loader/entries/6a1146d0015b4973beb5ff90a45b3909-6.11.8-yuan+.conf
参考:
https://docs.fedoraproject.org/en-US/quick-docs/kernel-build-custom/
https://discussion.fedoraproject.org/t/set-default-boot-to-console-mode-fedora-40/127893