一、簡介
我们使用 Linux 来表示整个操作系统,但严格地来说,Linux 只是个内核。各种发行版(RedHat、ubuntu、CentOS等)是一个完整功能的系统,它建立在内核之上,具有各种各样的应用程序工具和库。
关于内核版本的定义: 版本性质:主分支ml(mainline),稳定版(stable),长期维护版lt(longterm) 版本命名格式为 “A.B.C”: 数字 A 是内核版本号:版本号只有在代码和内核的概念有重大改变的时候才会改变,历史上有两次变化: 第一次是1994年的 1.0 版,第二次是1996年的 2.0 版,第三次是2011年的 3.0 版发布,但这次在内核的概念上并没有发生大的变化 数字 B 是内核主版本号:主版本号根据传统的奇-偶系统版本编号来分配:奇数为开发版,偶数为稳定版 数字 C 是内核次版本号:次版本号是无论在内核增加安全补丁、修复bug、实现新的特性或者驱动时都会改变
二、開始
1.查看當前内核版本
[root@VM-0-4-centos ~]# uname -rs Linux 3.10.0-1160.59.1.el7.x86_64
2.下載官方最新内核
這裏以 CentOS 7 爲例,鄙人這裏選擇的是 kernel-lt-5.4.183-1.el7.elrepo.x86_64.rpm (2022年3月8日發佈)
[root@VM-0-4-centos ~]# curl -LO https://elrepo.org/linux/kernel/el7/x86_64/RPMS/kernel-lt-5.4.183-1.el7.elrepo.x86_64.rpm [root@VM-0-4-centos ~]# rpm -ivh kernel-lt-5.4.183-1.el7.elrepo.x86_64.rpm
3.修改 grub 中默认的内核版本
内核升级完毕后,目前内核还是默认的版本,如果此时直接执行 reboot 命令,重启后使用的内核版本还是默认的 3.10,不会使用新的 5.4.183
# 查看默認啓動順序 [root@VM-0-4-centos ~]# awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg 0 : CentOS Linux (5.4.183-1.el7.elrepo.x86_64) 7 (Core) 1 : CentOS Linux (3.10.0-1160.59.1.el7.x86_64) 7 (Core) 2 : CentOS Linux (3.10.0-1160.11.1.el7.x86_64) 7 (Core) 3 : CentOS Linux (0-rescue-97d267522dd843d7930c95b4f627cb74) 7 (Core) 4 : CentOS Linux (0-rescue-3a6d3fd1db2b4ab6983389e8c068011e) 7 (Core
由上面可以看出新内核 (5.4.183) 目前位置在 0,原来的内核 (3.10.0) 目前位置在 1,所以如果想生效最新的内核,还需要修改内核的启动顺序为 0:
4. 修改内核啓動順序:vim /etc/default/grub
... ... ... GRUB_DEFAULT=0 ... ... ...
5.重新創建内核配置
[root@VM-0-4-centos ~]# grub2-mkconfig -o /boot/grub2/grub.cfg Generating grub configuration file … Found linux image: /boot/vmlinuz-5.4.183-1.el7.elrepo.x86_64 Found initrd image: /boot/initramfs-5.4.183-1.el7.elrepo.x86_64.img Found linux image: /boot/vmlinuz-3.10.0-1160.59.1.el7.x86_64 Found initrd image: /boot/initramfs-3.10.0-1160.59.1.el7.x86_64.img Found linux image: /boot/vmlinuz-3.10.0-1160.11.1.el7.x86_64 Found initrd image: /boot/initramfs-3.10.0-1160.11.1.el7.x86_64.img Found linux image: /boot/vmlinuz-0-rescue-97d267522dd843d7930c95b4f627cb74 Found initrd image: /boot/initramfs-0-rescue-97d267522dd843d7930c95b4f627cb74.img Found linux image: /boot/vmlinuz-0-rescue-3a6d3fd1db2b4ab6983389e8c068011e Found initrd image: /boot/initramfs-0-rescue-3a6d3fd1db2b4ab6983389e8c068011e.img done
6.重新啓動伺服器並查看内核是否生效
[root@VM-0-4-centos ~]# reboot ... ... ... [root@VM-0-4-centos ~]# uname -rs Linux 5.4.183-1.el7.elrepo.x86_64
三、説明
kernel-lt
- The Linux kernel. (The core of any Linux-based operating system.)
- 最核心的包,所有Linux系统的基础
kernel-lt-devel
- Development package for building kernel modules to match the kernel.
- 内核开发包,更多是提供给内核开发人员开发内核的一些功能模块
kernel-lt-doc
- Various bits of documentation found in the kernel sources.
- 内核包的指引文档
kernel-lt-headers
- Header files of the kernel, for use by glibc.
- 内核的头文件,一般其他应用需要调用内核能力就要引入这些头文件
kernel-lt-tools
- Assortment of tools for the kernel.
- 内核级别的一些工具
kernel-lt-tools-libs
- Libraries for the kernel tools.
- 内核级别工具所依赖的包
kernel-lt-tools-libs-devel
- Development package for the kernel tools libraries.
- 内核级别工具开发所需的依赖包