CentOS 更换内核
发表于更新于
北京
Linux 系统包含两个版本,一个是 Linux 发行版的版本(如 CentOS 7.6),另一个是内核版本(如 3.10.0-957),通过以下命令可以查看两个的版本:
1 2 3 4 5 6 7
| $ cat /etc/redhat-release CentOS Linux release 7.6.1810 (Core)
$ uname -r 3.10.0-957.el7.x86_64
|
一、更换 CentOS 发行版本
前往 CentOS Vault 仓库寻找自己需要的版本,这里包括基本所有需要的 CentOS 历史版本,但需要注意它通常不包括 LTS 版本(长期支持,如 CentOS 7.9,这类版本会存储于 CentOS 主仓库)。
https://mirrors.tuna.tsinghua.edu.cn/centos-vault/
这里以 7.6.1810 版本为例,需要执行以下命令:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| $ wget https://mirrors.tuna.tsinghua.edu.cn/centos-vault/7.6.1810/os/x86_64/Packages/centos-release-7-6.1810.2.el7.centos.x86_64.rpm
$ rpm -ivh centos-release-7-6.1810.2.el7.centos.x86_64.rpm --force
$ rpm -qa | grep -i centos-release centos-release-7-8.2003.0.el7.centos.x86_64 centos-release-7-6.1810.2.el7.centos.x86_64
$ rpm -ev centos-release-7-8.2003.0.el7.centos.x86_64
$ reboot
|
二、更换内核版本
首先下载内核包括两种方法,一种是基于 Vault 源,另一种是基于 ELRepo 源:
1. 基于 YUM 源
如果想更换的内核正好属于某个 CentOS 发行版本的默认内核(对应关系如下表),则可以通过替换 YUM 源的方式进行,具体步骤如下:
| CentOS 版本 |
发行时间 |
默认 Linux 内核版本 |
| 7.0.1406/ |
07-Apr-2015 15:36 |
kernel-3.10.0-123.el7.src.rpm |
| 7.1.1503/ |
13-Nov-2015 13:01 |
kernel-3.10.0-229.el7.src.rpm |
| 7.2.1511/ |
16-Feb-2016 16:15 |
kernel-3.10.0-327.el7.src.rpm |
| 7.3.1611/ |
2017-02-20 22:21 |
kernel-3.10.0-514.el7.src.rpm |
| 7.4.1708/ |
2018-02-26 14:32 |
kernel-3.10.0-693.el7.src.rpm |
| 7.5.1804/ |
2018-05-09 20:39 |
kernel-3.10.0-862.el7.src.rpm |
| 7.6.1810/ |
2018-12-02 14:34 |
kernel-3.10.0-957.el7.src.rpm |
| 7.7.1908/ |
2019-09-15 01:00 |
kernel-3.10.0-1062.el7.src.rpm |
| 7.8.2003/ |
2020-06-17 17:55 |
kernel-3.10.0-1127.el7.src.rpm |
| 7.9.2009/ |
2020-11-09 22:01 |
kernel-3.10.0-1160.el7.src.rpm |
| 8.0.1905/ |
2020-09-09 07:43 |
kernel-4.18.0-80.el8.src.rpm |
| 8.1.1911/ |
2020-04-13 08:20 |
kernel-4.18.0-147.el8.src.rpm |
| 8.2.2004/ |
2020-06-15 12:42 |
kernel-4.18.0-193.el8.src.rpm |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
$ echo "# C7.6.1810 [C7.6.1810-base] name=CentOS-7.6.1810 - Base baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/7.6.1810/os/\$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 enabled=1" >> /etc/yum.repos.d/CentOS-Vault.repo
$ yum makecache
$ yum list kernel --showduplicates
Installed Packages kernel.x86_64 3.10.0-957.el7 @base kernel.x86_64 3.10.0-1160.el7 @anaconda Available Packages kernel.x86_64 3.10.0-957.el7 C7.6.1810-base kernel.x86_64 3.10.0-1160.el7 base kernel.x86_64 3.10.0-1160.el7 updates kernel.x86_64 3.10.0-1160.2.1.el7 updates
$ yum install kernel-3.10.0-957.el7
$ cat /boot/grub2/grub.cfg | grep menuentry
menuentry 'CentOS Linux (3.10.0-957.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-1160.el7.x86_64-advanced-8add9029-af05-4660-8c1c-37e6fd7b1ac5' { menuentry 'CentOS Linux (3.10.0-1160.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-1160.el7.x86_64-advanced-8add9029-af05-4660-8c1c-37e6fd7b1ac5' {
$ grub2-set-default "CentOS Linux (3.10.0-957.el7.x86_64) 7 (Core)"
$ reboot
|
2. 基于 ELRepo
如果希望下载最新的内核版本,可以使用 ELRepo 源进行安装,具体如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| $ rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
$ yum install -y https://www.elrepo.org/elrepo-release-7.el7.elrepo.noarch.rpm
$ sed -e "s|mirrorlist=|#mirrorlist=|g" \ -e "s|elrepo.org/linux|mirrors.tuna.tsinghua.edu.cn/elrepo|g"\ -i.bak \ /etc/yum.repos.d/elrepo.repo
$ yum makecache
$ yum --disablerepo="*" --enablerepo="elrepo-kernel" list available
Available Packages kernel-lt.x86_64 5.4.202-1.el7.elrepo elrepo-kernel kernel-lt-devel.x86_64 5.4.202-1.el7.elrepo elrepo-kernel kernel-lt-doc.noarch 5.4.202-1.el7.elrepo elrepo-kernel kernel-lt-headers.x86_64 5.4.202-1.el7.elrepo elrepo-kernel kernel-lt-tools.x86_64 5.4.202-1.el7.elrepo elrepo-kernel kernel-lt-tools-libs.x86_64 5.4.202-1.el7.elrepo elrepo-kernel kernel-lt-tools-libs-devel.x86_64 5.4.202-1.el7.elrepo elrepo-kernel kernel-ml.x86_64 5.18.8-1.el7.elrepo elrepo-kernel kernel-ml-devel.x86_64 5.18.8-1.el7.elrepo elrepo-kernel kernel-ml-doc.noarch 5.18.8-1.el7.elrepo elrepo-kernel kernel-ml-headers.x86_64 5.18.8-1.el7.elrepo elrepo-kernel kernel-ml-tools.x86_64 5.18.8-1.el7.elrepo elrepo-kernel kernel-ml-tools-libs.x86_64 5.18.8-1.el7.elrepo elrepo-kernel kernel-ml-tools-libs-devel.x86_64 5.18.8-1.el7.elrepo elrepo-kernel
$ yum --enablerepo=elrepo-kernel install kernel-ml -y
$ cat /boot/grub2/grub.cfg | grep menuentry
menuentry 'CentOS Linux (3.10.0-957.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-1160.el7.x86_64-advanced-8add9029-af05-4660-8c1c-37e6fd7b1ac5' { menuentry 'CentOS Linux (3.10.0-1160.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-1160.el7.x86_64-advanced-8add9029-af05-4660-8c1c-37e6fd7b1ac5' {
$ grub2-set-default "CentOS Linux (3.10.0-957.el7.x86_64) 7 (Core)"
$ reboot
|