在本教程中,我们将学习如何在多个 Linux 发行版上安装最新的内核版本。
什么是内核
首先,让我们定义内核的定义。 Linux 内核基本上是硬件的大脑。 它的主要目的是促进硬件和软件之间的通信。 作为一个 example,如果应用程序需要进行更改(比如切换显示器的屏幕分辨率),软件会向内核提交请求,内核使用可用的视频驱动程序选项来修改分辨率。
有五种类型的内核可用。 它们的特点如下:
- 微内核:微内核的操作类似于单片内核,但它被设计得更小。 它只管理基本功能,如内存管理、进程间通信和多任务功能。
- 单片内核:单片内核使用占用相同内存区域的主内核线程来运行许多计算机系统服务。
- 混合内核:混合内核是一种架构,它是微内核和单片内核架构的聚合。 这种设计向内核空间添加了额外的代码以提高性能。
- 外核:exokernel 是一种在 MIT(麻省理工学院)创建的操作系统形式,可提供硬件资产的应用程序级管理。
- 纳米内核:nano 内核是允许硬件抽象的微内核,但缺乏对其他计算机系统的控制。 这个内核比传统的微内核更小。
现在我们对内核是什么以及它可以做什么有了基本的了解,让我们安装和/或更新我们的内核到最新版本。 我们将介绍内核在以下操作系统上的基本安装:
- 中央操作系统
- Ubuntu
- Debian
注意:请记住,在进行任何系统范围的更改之前,您应该始终对系统进行备份。
内核安装
首先,我们将介绍 CentOS 7 和新发布的 CentOS 8 版本的内核安装。让我们从 CentOS 7 开始。
(我们今天只讨论 64 位版本。)
CentOS 7
首先,我们需要确保我们所有的包都是最新的。 为此,我们将运行 yum update 命令。
[root@host ~]# yum -y update
接下来,我们要确认我们使用的是 CentOS 7。我们的命令输出将如下所示。
[root@host ~]# cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)
root@host [~]#
在此之后,让我们检查一下我们当前的内核版本。 当我们运行 uname 命令时,它会返回与此类似的输出。 (您系统上的内核版本号可能与下面显示的不同)
[root@host ~]# uname -srv
Linux 3.10.0-1062.4.0.el7.x86_64 #1 SMP Fri Oct 18 17:15:30 UTC 2019
如果我们分解这个输出,它表示以下有关内核版本的信息。
- Linux = 这是开源操作系统
- 3.10.0-1062.4.0.el7.x86_64 = 这是内核版本
- #1 SMP Fri Oct 18 17:15:30 UTC 2019 = 这是内核发布日期
现在我们知道了内核版本,我们可以将其与最新版本进行比较 可用的内核版本. 然后我们可以添加新的存储库来接收最新的内核版本。 我们将使用支持多个基于 RedHat/CentOS 的操作系统的 ELRepo(或 Enterprise Linux 软件包)存储库。 我们可以使用以下命令完成此任务。
[root@host ~]# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
如果之前没有将存储库添加到您的系统中,此命令将仅提供输出。 接下来,我们将运行命令来安装存储库。
[root@host ~]# rpm -Uvh https://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
在此之后,我们将验证存储库是否正确安装,并确保 ELRepo 包含在我们的可用存储库列表中。
[root@host ~]# yum repolist
Loaded plugins: fastestmirror, priorities
Loading mirror speeds from cached hostfile
* base: mirrors.BYNSS.com
* elrepo: ord.mirror.rackspace.com
* epel: mirrors.BYNSS.com
* extras: ftpmirror.your.org
* remi: mirror.pit.teraswitch.com
* remi-php56: mirror.pit.teraswitch.com
* remi-safe: mirror.pit.teraswitch.com
* updates: mirror.tzulo.com
repo id repo name status
base/7/x86_64 CentOS-7 - Base 10,097
bintray--ookla-rhel bintray--ookla-rhel 5
elrepo ELRepo.org Community Enterprise Linux Repository - el7 129
epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 13,188
extras/7/x86_64 CentOS-7 - Extras 323
remi Remi's RPM repository for Enterprise Linux 7 - x86_64 6,024
remi-php56 Remi's PHP 5.6 RPM repository for Enterprise Linux 7 - x86_64 441
remi-safe Safe Remi's RPM repository for Enterprise Linux 7 - x86_64 3,676
updates/7/x86_64 CentOS-7 - Updates 1,446
repolist: 35,329
我们可以看到 ELRepo 确实包含在我们的列表中。 我们唯一要做的就是安装新的内核版本。 我们可以使用以下命令部署新内核。
[root@host ~]# yum --enablerepo=elrepo-kernel install kernel-ml
这 ”毫升” 添加代表“主线稳定”,这表明内核是从内核档案的稳定分支安装的。 您可以再次检查您的内核版本,它将是可用的最新版本。 现在,当我们运行 uname 命令时,我们的输出将如下所示。
[root@host ~]# uname -srv
Package kernel-ml-5.5.4-1.el7.elrepo.x86_64 installed

CentOS 8
我们可以按照上面用于 CentOS 7 的相同步骤进行操作,直到我们到达存储库安装步骤。
[root@host ~]# yum -y update
[root@host ~]# cat /etc/redhat-release
[root@host ~]# uname -srv
[root@host ~]# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
在我们使用 rpm –import 命令为 ELRepo 存储库添加 RPM-GPG-KEY 后,我们将运行以下 dnf 命令来添加存储库。
[root@host ~]# dnf install https://www.elrepo.org/elrepo-release-8.0-2.el8.elrepo.noarch.rpm
在安装过程中,我们会被提示选择’是的‘ 或者 ”n‘,接受部署。 类型 ‘是的‘ 并且内核将被安装。 输出将如下所示。
Installed:
elrepo-release-8.0-2.el8.elrepo.noarch
接下来,我们将使用 dnf 命令检查已安装存储库的列表。
[root@host ~]# dnf repolist
Last metadata expiration check: 0:02:47 ago on Mon 17 Feb 2020 07:00:54 AM EST.
repo id repo name status
AppStream CentOS-8 - AppStream 5,093
BaseOS CentOS-8 - Base 2,080
elrepo ELRepo.org Community Enterprise Linux Repository - el8 69
extras CentOS-8 - Extras 3
确认安装了 ELRepo 后,我们就可以更新到最新的内核版本了。
[root@host ~]# dnf --enablerepo=elrepo-kernel install kernel-ml
Installed:
kernel-ml-5.5.4-1.el8.elrepo.x86_64 kernel-ml-modules-5.5.4-1.el8.elrepo.x86_64 kernel-ml-core-5.5.4-1.el8.elrepo.x86_64
就是这样! 您现在知道如何在 CentOS 7 和 CentOS 8 上升级内核了。

Ubuntu 18
首先,我们将运行以下命令以确保我们的系统是最新的。 此命令将更新我们系统上的所有存储库。
root@ubuntu:~# apt update
接下来,我们将运行 apt upgrade 命令来升级当前安装的所有软件包。
Next, we will run the apt upgrade command to upgrade all packages that are currently installed.
现在我们可以使用 uname 命令验证我们当前正在运行的内核版本。
root@ubuntu:~# uname -msr
Linux 4.4.0-78-generic x86_64
接下来,我们需要创建一个目录来临时存储最新的主线内核版本。 现在,我们将使用以下命令创建目录。
root@ubuntu:~# mkdir -p ~/4.15.0
接下来,让 cd 进入我们刚刚创建的新文件夹。
root@ubuntu:~# cd ~/4.15.0
现在我们可以使用 wget 命令下载最新的通用内核版本。 在这里您可以找到最新的 内核 PPA ubuntu 的版本。 我们将用来下载内核的命令将如下所示。
root@ubuntu:~/4.15.0# wget https://kernel.ubuntu.com/~kernel-ppa/mainline/drm-intel-nightly/current/linux-headers-5.6.0-994_5.6.0-994.202002162102_all.deb
注意:这只是 example. 您应该下载所需的内核版本。
然后,我们可以使用 dpkg I 命令安装下载的内核包。
root@ubuntu:~/4.15.0# dpkg -i *.deb
最后,您需要做的就是运行 update-grub 命令并重新启动系统。
root@ubuntu:~/4.15.0# update-grub
Sourcing file `/etc/default/grub'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.15.0-88-generic
Found initrd image: /boot/initrd.img-4.15.0-88-generic
Found linux image: /boot/vmlinuz-4.15.0-70-generic
Found initrd image: /boot/initrd.img-4.15.0-70-generic
Found linux image: /boot/vmlinuz-4.15.0-66-generic
Found initrd image: /boot/initrd.img-4.15.0-66-generic
Found linux image: /boot/vmlinuz-4.15.0-13-generic
Found initrd image: /boot/initrd.img-4.15.0-13-generic
Found linux image: /boot/vmlinuz-4.11.2-041102-generic
Found initrd image: /boot/initrd.img-4.11.2-041102-generic
done
root@ubuntu:~/4.15.0# reboot
就是这样! Ubuntu 内核已升级。

Debian 10(克星)
最初,我们将检查我们当前安装的内核版本是什么。
root@host:/# uname -r
4.19.0-6-amd64
接下来,我们将确保我们所有的软件包都已更新。
root@host:/# aptitude update
然后,我们需要使用此命令搜索任何可用的内核。
root@host:/# aptitude search linux-image
输出将为我们提供相当长的可用内核列表。
linux-image-unsigned-5.3.0-1010-azure - Linux kernel image for version 5.3.0 on 64 bit x86 SMP
linux-image-unsigned-5.3.0-1011-gcp - Linux kernel image for version 5.3.0 on 64 bit x86 SMP
linux-image-unsigned-5.3.0-1012-azure - Linux kernel image for version 5.3.0 on 64 bit x86 SMP
linux-image-unsigned-5.3.0-1012-gcp - Linux kernel image for version 5.3.0 on 64 bit x86 SMP
linux-image-unsigned-5.3.0-1013-azure - Linux kernel image for version 5.3.0 on 64 bit x86 SMP
linux-image-unsigned-5.3.0-29-generic - Linux kernel image for version 5.3.0 on 64 bit x86 SMP
linux-image-unsigned-5.3.0-29-lowlatency - Linux kernel image for version 5.3.0 on 64 bit x86 SMP
linux-image-unsigned-5.3.0-40-generic - Linux kernel image for version 5.3.0 on 64 bit x86 SMP
linux-image-unsigned-5.3.0-40-lowlatency - Linux kernel image for version 5.3.0 on 64 bit x86 SMP
linux-modules-nvidia-390-5.3.0-1010-aws - Linux kernel nvidia modules for version 5.3.0-1010
linux-modules-nvidia-390-5.3.0-1010-azure - Linux kernel nvidia modules for version 5.3.0-1010
linux-modules-nvidia-390-5.3.0-1011-aws - Linux kernel nvidia modules for version 5.3.0-1011
linux-modules-nvidia-390-5.3.0-1011-gcp - Linux kernel nvidia modules for version 5.3.0-1011
linux-modules-nvidia-390-5.3.0-1012-azure - Linux kernel nvidia modules for version 5.3.0-1012
linux-modules-nvidia-390-5.3.0-1012-gcp - Linux kernel nvidia modules for version 5.3.0-1012
linux-modules-nvidia-390-5.3.0-1013-azure - Linux kernel nvidia modules for version 5.3.0-1013
linux-modules-nvidia-435-5.3.0-26-generic - Linux kernel nvidia modules for version 5.3.0-26
linux-modules-nvidia-435-5.3.0-26-lowlatency - Linux kernel nvidia modules for version 5.3.0-26
linux-modules-nvidia-435-5.3.0-29-generic - Linux kernel nvidia modules for version 5.3.0-29
linux-modules-nvidia-435-5.3.0-29-lowlatency - Linux kernel nvidia modules for version 5.3.0-29
linux-modules-nvidia-435-5.3.0-40-generic - Linux kernel nvidia modules for version 5.3.0-40
linux-modules-nvidia-435-5.3.0-40-lowlatency - Linux kernel nvidia modules for version 5.3.0-40
linux-image-5.0.0-1025-oem-osp1 - Signed kernel image oem-osp1
linux-image-5.0.0-1030-oem-osp1 - Signed kernel image oem-osp1
linux-image-5.0.0-1033-oem-osp1 - Signed kernel image oem-osp1
linux-image-5.0.0-1037-oem-osp1 - Signed kernel image oem-osp1
linux-image-oem-osp1 - OEM OSP1 Linux kernel image
linux-image-unsigned-5.0.0-1025-oem-osp1 - Linux kernel image for version 5.0.0 on 64 bit x86 SMP
linux-image-unsigned-5.0.0-1030-oem-osp1 - Linux kernel image for version 5.0.0 on 64 bit x86 SMP
linux-image-unsigned-5.0.0-1033-oem-osp1 - Linux kernel image for version 5.0.0 on 64 bit x86 SMP
linux-image-unsigned-5.0.0-1037-oem-osp1 - Linux kernel image for version 5.0.0 on 64 bit x86 SMP
我们可以通过使用 grep 命令将输出限制为一组特定的内核版本来进一步缩小命令行输出。
root@host:/# aptitude search linux-image | grep 4.15
linux-image-4.15.0-1050-oem - Signed kernel image oem
linux-image-unsigned-4.15.0-1050-oem - Linux kernel image for version 4.15.0 on 64 bit x86 SMP
linux-image-4.15.0-1059-oem - Signed kernel image oem
linux-image-4.15.0-1065-oem - Signed kernel image oem
linux-image-4.15.0-1066-oem - Signed kernel image oem
linux-image-4.15.0-1067-oem - Signed kernel image oem
linux-image-unsigned-4.15.0-1059-oem - Linux kernel image for version 4.15.0 on 64 bit x86 SMP
linux-image-unsigned-4.15.0-1065-oem - Linux kernel image for version 4.15.0 on 64 bit x86 SMP
linux-image-unsigned-4.15.0-1066-oem - Linux kernel image for version 4.15.0 on 64 bit x86 SMP
linux-image-unsigned-4.15.0-1067-oem - Linux kernel image for version 4.15.0 on 64 bit x86 SMP
现在,我们可以选择要安装的最新内核版本或特定版本。 选择内核包后,运行此命令进行安装。
root@host:/# aptitude install linux-image-4.15.0-1059-oem
注意:这只是 example 我们安装的内核版本来演示该命令。
就是这样! 我们完了。 您选择的内核版本已安装在您的 Debian 系统上。
愿意加入我们吗? 看看你是否符合条件!
Liquid Web 提供多种计划和产品,可满足您的所有托管需求! 我们的客户还可以从广泛的附加托管选项中进行选择,以及其他绝对可以解决任何需求或疑虑的精选机会。 我们以成为“Hosting® 中最有帮助的人”而自豪,我们的客户也同意!