Centos7 升级内核版本

1、查看当前内核版本

 

$ uname -r
3.10.0-957.21.3.el7.x86_64

$ uname -a
Linux localhost.localdomain 3.10.0-957.21.3.el7.x86_64 #1 SMP Tue Jun 18 16:35:19 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

$ cat /etc/redhat-release 
CentOS Linux release 7.7.1908 (Core)

 

2、升级内核

更新yum源仓库

$ yum -y update

启用 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 http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm

 

Star Get started
Import the public key:

rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org (external link)

Detailed info on the GPG key used by the ELRepo Project can be found on https://www.elrepo.org/tiki/key (external link)
If you have a system with Secure Boot enabled, please see the SecureBootKey page for more information.

To install ELRepo for RHEL-8 or CentOS-8:

yum install https://www.elrepo.org/elrepo-release-8.0-2.el8.elrepo.noarch.rpm (external link)

To make use of our mirror system, please also install yum-plugin-fastestmirror.

To install ELRepo for RHEL-7, SL-7 or CentOS-7:

yum install https://www.elrepo.org/elrepo-release-7.0-4.el7.elrepo.noarch.rpm (external link)

To make use of our mirror system, please also install yum-plugin-fastestmirror.

To install ELRepo for RHEL-6, SL-6 or CentOS-6:

yum install https://www.elrepo.org/elrepo-release-6-9.el6.elrepo.noarch.rpm (external link)

To make use of our mirror system, please also install yum-plugin-fastestmirror.

 

3、查看可用的系统内核包

 

 

[root@localhost]# yum --disablerepo="*" --enablerepo="elrepo-kernel" list available
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * elrepo-kernel: mirror-hk.koddos.net
Available Packages
kernel-lt.x86_64                        4.4.210-1.el7.elrepo       elrepo-kernel
kernel-lt-devel.x86_64                  4.4.210-1.el7.elrepo       elrepo-kernel
kernel-lt-doc.noarch                    4.4.210-1.el7.elrepo       elrepo-kernel
kernel-lt-headers.x86_64                4.4.210-1.el7.elrepo       elrepo-kernel
kernel-lt-tools.x86_64                  4.4.210-1.el7.elrepo       elrepo-kernel
kernel-lt-tools-libs.x86_64             4.4.210-1.el7.elrepo       elrepo-kernel
kernel-lt-tools-libs-devel.x86_64       4.4.210-1.el7.elrepo       elrepo-kernel
kernel-ml-devel.x86_64                  5.4.12-1.el7.elrepo        elrepo-kernel
kernel-ml-doc.noarch                    5.4.12-1.el7.elrepo        elrepo-kernel
kernel-ml-headers.x86_64                5.4.12-1.el7.elrepo        elrepo-kernel
kernel-ml-tools.x86_64                  5.4.12-1.el7.elrepo        elrepo-kernel
kernel-ml-tools-libs.x86_64             5.4.12-1.el7.elrepo        elrepo-kernel
kernel-ml-tools-libs-devel.x86_64       5.4.12-1.el7.elrepo        elrepo-kernel
perf.x86_64                             5.4.12-1.el7.elrepo        elrepo-kernel
python-perf.x86_64                      5.4.12-1.el7.elrepo        elrepo-kernel

 

4、安装最新版本内核

[root@localhost]# yum --enablerepo=elrepo-kernel install kernel-ml
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * elrepo: hkg.mirror.rackspace.com
 * elrepo-kernel: hkg.mirror.rackspace.com
Package kernel-ml-5.4.12-1.el7.elrepo.x86_64 already installed and latest version
Nothing to do

--enablerepo 选项开启 CentOS 系统上的指定仓库。默认开启的是 elrepo,这里用 elrepo-kernel 替换。

5、设置 grub2

内核安装好后,需要设置为默认启动选项并重启后才会生效

查看系统上的所有可用内核:

$ sudo awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg
0 : CentOS Linux (5.4.12-1.el7.elrepo.x86_64) 7 (Core)
1 : CentOS Linux (3.10.0-1062.9.1.el7.x86_64) 7 (Core)
2 : CentOS Linux (3.10.0-1062.1.2.el7.x86_64) 7 (Core)
3 : CentOS Linux (3.10.0-957.21.3.el7.x86_64) 7 (Core)
4 : CentOS Linux (3.10.0-693.el7.x86_64) 7 (Core)
5 : CentOS Linux (0-rescue-e552d1c51b3b48ad8774af5e159eca4f) 7 (Core)

设置新的内核为grub2的默认版本

服务器上存在4 个内核,我们要使用 5.4这个版本,可以通过 grub2-set-default 0 命令或编辑 /etc/default/grub 文件来设置

方法1、通过 grub2-set-default 0 命令设置

其中 0 是上面查询出来的可用内核

grub2-set-default 0

方法2、编辑 /etc/default/grub 文件

设置 GRUB_DEFAULT=0,通过上面查询显示的编号为 0 的内核作为默认内核:

 

$ vim /etc/default/grub
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=0
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=cl/root rhgb quiet"
GRUB_DISABLE_RECOVERY="true"

 

生成 grub 配置文件并重启

 

[root@localhost]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.4.12-1.el7.elrepo.x86_64
Found initrd image: /boot/initramfs-5.4.12-1.el7.elrepo.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-1062.9.1.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-1062.9.1.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-1062.1.2.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-1062.1.2.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-957.21.3.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-957.21.3.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-693.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-693.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-e552d1c51b3b48ad8774af5e159eca4f
Found initrd image: /boot/initramfs-0-rescue-e552d1c51b3b48ad8774af5e159eca4f.img
done


[root@localhost]#reboot

 

6、验证

[root@localhost ~]# uname -r
5.4.12-1.el7.elrepo.x86_64

7、删除旧内核(可选)

查看系统中全部的内核:

[root@localhost ~]# rpm -qa | grep kernel
kernel-tools-libs-3.10.0-1062.9.1.el7.x86_64
kernel-3.10.0-1062.9.1.el7.x86_64
kernel-3.10.0-693.el7.x86_64
kernel-3.10.0-957.21.3.el7.x86_64
kernel-3.10.0-1062.1.2.el7.x86_64
kernel-tools-3.10.0-1062.9.1.el7.x86_64
kernel-ml-5.4.12-1.el7.elrepo.x86_64

方法1、yum remove 删除旧内核的 RPM 包

$ yum remove kernel-3.10.0-514.el7.x86_64 \
kernel-tools-libs-3.10.0-862.11.6.el7.x86_64 \
kernel-tools-3.10.0-862.11.6.el7.x86_64 \
kernel-3.10.0-862.11.6.el7.x86_64

方法2、yum-utils 工具

如果安装的内核不多于 3 个,yum-utils 工具不会删除任何一个。只有在安装的内核大于 3 个时,才会自动删除旧内核。

安装yum-utils

$ yum install yum-utils

删除旧版本  

package-cleanup --oldkernels

 

 

 

 

Welcome to the ELRepo Project

"For the community, by the community."

Welcome to ELRepo, an RPM repository for Enterprise Linux packages. ELRepo supports Red Hat Enterprise Linux (RHEL) and its derivatives (Scientific Linux, CentOS & others).

The ELRepo Project focuses on hardware related packages to enhance your experience with Enterprise Linux. This includes filesystem drivers, graphics drivers, network drivers, sound drivers, webcam and video drivers.


 

Star Get started

Import the public key:
 

rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org(external link)


Detailed info on the GPG key used by the ELRepo Project can be found on https://www.elrepo.org/tiki/key(external link)
If you have a system with Secure Boot enabled, please see the SecureBootKey page for more information.

To install ELRepo for RHEL-8 or CentOS-8:
 

yum install https://www.elrepo.org/elrepo-release-8.0-2.el8.elrepo.noarch.rpm(external link)


To make use of our mirror system, please also install yum-plugin-fastestmirror.

To install ELRepo for RHEL-7, SL-7 or CentOS-7:
 

yum install https://www.elrepo.org/elrepo-release-7.0-4.el7.elrepo.noarch.rpm(external link)


To make use of our mirror system, please also install yum-plugin-fastestmirror.

To install ELRepo for RHEL-6, SL-6 or CentOS-6:
 

yum install https://www.elrepo.org/elrepo-release-6-9.el6.elrepo.noarch.rpm(external link)


To make use of our mirror system, please also install yum-plugin-fastestmirror.


 

Star Repository contents

ELRepo contains four channels. You can browse the contents of each channel by clicking on its name.
 

elrepo

This is the main channel and is enabled by default. As this channel should not contain packages also present in the distribution, it should be safe to run a 'yum update' with this repository channel enabled.

For example, to install kmod-r8168 (Realtek r8168 NIC driver):
 

yum install kmod-r8168


Depending on the package being installed or the repository setup, it might be necessary to disable non-elrepo repositories:
 

yum --disablerepo=\* --enablerepo=elrepo install kmod-nvidia

 

elrepo-extras

The elrepo-extras channel provides packages and their dependencies that replace/update RHEL distribution packages. It may be enabled in the /etc/yum.repos.d/elrepo.repo file or used with 'yum --enablerepo=elrepo-extras'.
 

elrepo-testing

The elrepo-testing channel provides packages yet to be released to the main channel and is disabled by default. It may be enabled in the /etc/yum.repos.d/elrepo.repo file or used with 'yum --enablerepo=elrepo-testing'.
 

elrepo-kernel

The elrepo-kernel channel provides both the long-term support kernels (which have been configured for RHEL-7 and RHEL-6) and the latest stable mainline kernels (which have been configured for RHEL-8 and RHEL-7) using sources available from the Linux Kernel Archives(external link). Please see the kernel-lt or kernel-ml pages for further details. This channel may be enabled in the /etc/yum.repos.d/elrepo.repo file or used with 'yum --enablerepo=elrepo-kernel'.
 

Help Need help?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值