当前位置: 首页 > 工具软件 > Ali-Kernel > 使用案例 >

CentOS7 如何升级kernel

公良信然
2023-12-01

1.查看当前内核版本

[root@wfp7-ae ~]# uname -a

Linux wfp7-ae 3.10.0-862.el7.x86_64 #1 SMP Fri Apr 20 16:44:24 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
[root@wfp7-ae ~]# cat /etc/redhat-release 
CentOS Linux release 7.8.2003 (Core)
[root@wfp7-ae ~]#

2.启用 ELRepo 仓库

ELRepo 仓库是基于社区的用于企业级 Linux 仓库,提供对 RedHat Enterprise (RHEL) 和 其他基于 RHEL的 Linux 发行版(CentOS、Scientific、Fedora 等)的支持。
ELRepo 聚焦于和硬件相关的软件包,包括文件系统驱动、显卡驱动、网络驱动、声卡驱动和摄像头驱动等。
#导入ELRepo仓库的公共密钥

rpm –import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org

#安装ELRepo仓库的yum源

rpm -Uvh  https://www.elrepo.org/elrepo-release-7.el7.elrepo.noarch.rpm #yum源

3. 查看可用的内核相关的包

[root@wfp7-ae Desktop]# yum --disablerepo="*" --enablerepo="elrepo-kernel" list available
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * elrepo-kernel: dfw.mirror.rackspace.com
elrepo-kernel                                                 | 2.9 kB  00:00:00     
elrepo-kernel/primary_db                                      | 1.9 MB  00:06:03     
Available Packages
kernel-lt.x86_64                          4.4.232-1.el7.elrepo          elrepo-kernel
kernel-lt-devel.x86_64                    4.4.232-1.el7.elrepo          elrepo-kernel
kernel-lt-doc.noarch                      4.4.232-1.el7.elrepo          elrepo-kernel
kernel-lt-headers.x86_64                  4.4.232-1.el7.elrepo          elrepo-kernel
kernel-lt-tools.x86_64                    4.4.232-1.el7.elrepo          elrepo-kernel
kernel-lt-tools-libs.x86_64               4.4.232-1.el7.elrepo          elrepo-kernel
kernel-lt-tools-libs-devel.x86_64         4.4.232-1.el7.elrepo          elrepo-kernel
kernel-ml.x86_64                          5.8.0-1.el7.elrepo            elrepo-kernel
kernel-ml-devel.x86_64                    5.8.0-1.el7.elrepo            elrepo-kernel
kernel-ml-doc.noarch                      5.8.0-1.el7.elrepo            elrepo-kernel
kernel-ml-headers.x86_64                  5.8.0-1.el7.elrepo            elrepo-kernel
kernel-ml-tools.x86_64                    5.8.0-1.el7.elrepo            elrepo-kernel
kernel-ml-tools-libs.x86_64               5.8.0-1.el7.elrepo            elrepo-kernel
kernel-ml-tools-libs-devel.x86_64         5.8.0-1.el7.elrepo            elrepo-kernel
perf.x86_64                               5.8.0-1.el7.elrepo            elrepo-kernel
python-perf.x86_64                        5.8.0-1.el7.elrepo            elrepo-kernel
[root@wfp7-ae Desktop]#

4.安装内核(已最新为例)

[root@wfp7-ae Desktop]# yum -y --enablerepo=elrepo-kernel install kernel-ml.x86_64 kernel-ml-devel.x86_64

5.修改grub中默认的内核版本

内核升级完成后,还需要调整

5.1查看内核启动顺序

awk -F’ ‘$1=="menuentry " {print $2}’ /etc/grub2.cfg
  通过此命令可以看到新内核顺序为0

5.2修改内核启动顺序为0
[root@wfp7-ae Desktop]# cat /etc/default/grub                                        
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
#GRUB_DEFAULT=saved
GRUB_DEFAULT=0
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet"
GRUB_DISABLE_RECOVERY="true"

各参数详解讲解:https://www.cnblogs.com/mylive/p/11280241.html

5.3接着用命令来创建内核配置
[root@wfp7-ae ~]# grub2-mkconfig -o /boot/grub2/grub.cfg                             
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.8.0-1.el7.elrepo.x86_64
Found initrd image: /boot/initramfs-5.8.0-1.el7.elrepo.x86_64.img
Found linux image: /boot/vmlinuz-4.19.91-007.ali4000.alios7.x86_64
Found initrd image: /boot/initramfs-4.19.91-007.ali4000.alios7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-1127.18.2.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-1127.18.2.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-862.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-862.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-0363392b5e204820ac99c5ca36fdca09
Found initrd image: /boot/initramfs-0-rescue-0363392b5e204820ac99c5ca36fdca09.img
done

6.重启查看变化

[root@wfp7-ae Desktop]# init 6

参考:https://www.cnblogs.com/zhangxingeng/p/10941781.html

 类似资料: