如何安装最新的内核版本

在本教程中,我们将学习如何在多个 Linux 发行版上安装最新的内核版本。

什么是内核

首先,让我们定义内核的定义。 Linux 内核基本上是硬件的大脑。 它的主要目的是促进硬件和软件之间的通信。 例如,如果应用程序需要进行更改(比如切换显示器的屏幕分辨率),软件会向内核提交请求,内核会使用可用的视频驱动程序选项来修改分辨率。

有五种类型的内核可用。 它们的特点如下:

  • 微内核:微内核的操作类似于单片内核,但它被设计得更小。 它只管理基本功能,如内存管理、进程间通信和多任务处理功能。
  • 单片内核:单体内核使用占据相同内存区域的主内核线程来运行许多计算机系统服务。
  • 混合内核:混合内核是一种架构,它是微内核和单片内核架构的聚合。 这种设计向内核空间添加了额外的代码以提高性能。
  • 外核:exokernel 是在 MIT(麻省理工学院)创建的一种操作系统形式,它提供硬件资产的应用程序级管理。
  • 纳米内核:nano 内核是一个允许硬件抽象的微内核,但缺乏对其他计算机系统的控制。 这个内核比传统的微内核更小。

现在我们对内核是什么以及它可以做什么有了基本的了解,让我们安装和/或更新我们的内核到最新版本。 我们将介绍内核在以下操作系统上的基本安装:

  • CentOS
  • Ubuntu
  • Debian

注意:请记住,在进行任何系统范围的更改之前,您应该始终备份系统。

内核安装

首先,我们将介绍 CentOS 7 和新发布的 CentOS 8 版本的内核安装。让我们从 CentOS 7 开始。
(我们今天只讨论 64 位版本。)

CentOS 7

首先,我们需要确保我们所有的软件包都是最新的。 为此,我们将运行 yum update 命令。

[[email protected] ~]# yum -y update

接下来,我们要确认我们使用的是 CentOS 7。我们的命令的输出将如下所示。

[[email protected] ~]# cat /etc/redhat-release CentOS Linux release 7.7.1908 (Core) [email protected] [~]#

在此之后,让我们检查我们当前的内核版本。 当我们运行 uname 命令时,它会返回类似的输出。 (您系统上的内核版本号可能与下图所示有所不同)

[[email protected] ~]# 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 包)存储库。 我们可以使用以下命令完成此任务。

[[email protected] ~]# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org

如果存储库之前未添加到您的系统,此命令将仅提供输出。 接下来,我们将运行命令来安装存储库。

[[email protected] ~]# rpm -Uvh https://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm

在此之后,我们将验证存储库是否正确安装,并确保 ELRepo 包含在我们的可用存储库列表中。

[[email protected] ~]# yum repolist Loaded plugins: fastestmirror, priorities Loading mirror speeds from cached hostfile  * base: mirrors.CodePre.com  * elrepo: ord.mirror.rackspace.com  * epel: mirrors.CodePre.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 确实包含在我们的列表中。 我们唯一要做的就是安装新的内核版本。 我们可以使用以下命令部署新内核。

[[email protected] ~]# yum --enablerepo=elrepo-kernel install kernel-ml

这 ”毫升”addition 代表“mainline stable”,这表示内核是从内核存档的稳定分支安装的。 您可以再次检查您的内核版本,它将是可用的最新版本。 现在,当我们运行 uname 命令时,我们的输出将如下所示。

[[email protected] ~]# uname -srv Package kernel-ml-5.5.4-1.el7.elrepo.x86_64 installed 
内核.red.2.20.20迈克尔·杰季奇 (Michael Dziedzic) 在 Unsplash 上的照片

CentOS 8

我们可以按照上面用于 CentOS 7 的相同步骤进行操作,直到到达存储库安装步骤。

[[email protected] ~]# yum -y update [[email protected] ~]# cat /etc/redhat-release [[email protected] ~]# uname -srv [[email protected] ~]# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org

在我们使用 rpm –import 命令为 ELRepo 存储库添加 RPM-GPG-KEY 后,我们将运行以下 dnf 命令来添加存储库。

[[email protected] ~]# 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 命令检查已安装的存储库列表。

[[email protected] ~]# 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 已安装后,我们准备更新到最新的内核版本。

[[email protected] ~]# 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 上升级内核了。

内核.blue.2.20.20Michael Dziedzic 在 Unsplash 上的照片

Ubuntu 18

首先,我们将运行以下命令以确保我们的系统是最新的。 此命令将更新我们系统上的所有存储库。

[email protected]:~# apt update

接下来,我们将运行 apt upgrade 命令来升级当前安装的所有软件包。

Next, we will run the apt upgrade command to upgrade all packages that are currently installed. 

现在我们可以使用 uname 命令验证我们当前正在运行的内核版本。

[email protected]:~# uname -msr Linux 4.4.0-78-generic x86_64

接下来,我们需要创建一个目录来临时存储最新的主线内核版本。 现在,我们将使用以下命令创建目录。

[email protected]:~# mkdir -p ~/4.15.0

接下来,让 cd 进入我们刚刚创建的新文件夹。

[email protected]:~# cd ~/4.15.0

现在我们可以使用 wget 命令下载最新的通用内核版本。 在这里你可以找到最新的 内核PPA ubuntu 的版本。 我们将用于下载内核的命令如下所示。

[email protected]:~/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

注意:这只是示例。 您应该下载所需的内核版本。

然后,我们可以使用 dpkg I 命令安装下载的内核包。

[email protected]:~/4.15.0# dpkg -i *.deb

最后,您需要做的就是运行 update-grub 命令并重新启动系统。

 [email protected]:~/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  [email protected]:~/4.15.0# reboot

就是这样! Ubuntu 内核已升级。

内核1.2.20.20

Debian 10(克星)

最初,我们将检查当前安装的内核版本是什么。

[email protected]:/# uname -r 4.19.0-6-amd64

接下来,我们将确保我们所有的包都得到更新。

[email protected]:/# aptitude update

然后,我们需要使用此命令搜索任何可用的内核。

[email protected]:/# 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 命令将输出限制为一组特定的内核版本来进一步缩小命令行输出的范围。

[email protected]:/# 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

现在,我们可以选择最新的内核版本或我们想要安装的特定版本。 选择内核包后,运行此命令进行安装。

[email protected]:/# aptitude install linux-image-4.15.0-1059-oem

注意:这只是我们为了演示命令而安装的示例内核版本。

就是这样! 我们完了。 您选择的内核版本已经安装在您的 Debian 系统上。

想加入我们吗? 看看你是否合格!

Liquid Web 提供了广泛的计划和产品选择,可以满足您所有的托管需求! 我们的客户还可以从广泛的附加托管选项中进行选择,以及其他绝对可以满足任何需求或顾虑的精选机会。 我们以成为“托管中最有帮助的人®”而自豪,我们的客户也同意!