在 Debian 9 上手动安装新内核的正确方法是什么?

Lin*_*eak 11 kernel debian

我没有足够的信心单独执行此操作并冒着服务器无法启动的风险。

我想从以下位置升级内核:

$ uname -r
4.9.0-6-amd64

$ uname -v
#1 SMP Debian 4.9.88-1+deb9u1 (2018-05-07)
Run Code Online (Sandbox Code Playgroud)

到内核​​版本 4.15 或 4.16。无论你推荐哪个。


我只是想我知道如何列出可用的版本:

$ apt-cache search linux-image | grep amd64

linux-headers-4.9.0-6-amd64 - Header files for Linux 4.9.0-6-amd64
linux-headers-4.9.0-6-rt-amd64 - Header files for Linux 4.9.0-6-rt-amd64
linux-image-4.9.0-6-amd64 - Linux 4.9 for 64-bit PCs
linux-image-4.9.0-6-amd64-dbg - Debug symbols for linux-image-4.9.0-6-amd64
linux-image-4.9.0-6-rt-amd64 - Linux 4.9 for 64-bit PCs, PREEMPT_RT
linux-image-4.9.0-6-rt-amd64-dbg - Debug symbols for linux-image-4.9.0-6-rt-amd64
linux-image-amd64 - Linux for 64-bit PCs (meta-package)
linux-image-amd64-dbg - Debugging symbols for Linux amd64 configuration (meta-package)
linux-image-rt-amd64 - Linux for 64-bit PCs (meta-package), PREEMPT_RT
linux-image-rt-amd64-dbg - Debugging symbols for Linux rt-amd64 configuration (meta-package)
linux-headers-4.9.0-3-amd64 - Header files for Linux 4.9.0-3-amd64
linux-headers-4.9.0-3-rt-amd64 - Header files for Linux 4.9.0-3-rt-amd64
linux-headers-4.9.0-4-amd64 - Header files for Linux 4.9.0-4-amd64
linux-headers-4.9.0-4-rt-amd64 - Header files for Linux 4.9.0-4-rt-amd64
linux-headers-4.9.0-5-amd64 - Header files for Linux 4.9.0-5-amd64
linux-headers-4.9.0-5-rt-amd64 - Header files for Linux 4.9.0-5-rt-amd64
linux-image-4.9.0-3-amd64 - Linux 4.9 for 64-bit PCs
linux-image-4.9.0-3-amd64-dbg - Debug symbols for linux-image-4.9.0-3-amd64
linux-image-4.9.0-3-rt-amd64 - Linux 4.9 for 64-bit PCs, PREEMPT_RT
linux-image-4.9.0-3-rt-amd64-dbg - Debug symbols for linux-image-4.9.0-3-rt-amd64
linux-image-4.9.0-4-amd64 - Linux 4.9 for 64-bit PCs
linux-image-4.9.0-4-amd64-dbg - Debug symbols for linux-image-4.9.0-4-amd64
linux-image-4.9.0-4-rt-amd64 - Linux 4.9 for 64-bit PCs, PREEMPT_RT
linux-image-4.9.0-4-rt-amd64-dbg - Debug symbols for linux-image-4.9.0-4-rt-amd64
linux-image-4.9.0-5-amd64 - Linux 4.9 for 64-bit PCs
linux-image-4.9.0-5-amd64-dbg - Debug symbols for linux-image-4.9.0-5-amd64
linux-image-4.9.0-5-rt-amd64 - Linux 4.9 for 64-bit PCs, PREEMPT_RT
linux-image-4.9.0-5-rt-amd64-dbg - Debug symbols for linux-image-4.9.0-5-rt-amd64
linux-headers-4.15.0-0.bpo.2-amd64 - Header files for Linux 4.15.0-0.bpo.2-amd64
linux-headers-4.15.0-0.bpo.2-cloud-amd64 - Header files for Linux 4.15.0-0.bpo.2-cloud-amd64
linux-headers-4.16.0-0.bpo.1-amd64 - Header files for Linux 4.16.0-0.bpo.1-amd64
linux-headers-4.16.0-0.bpo.1-cloud-amd64 - Header files for Linux 4.16.0-0.bpo.1-cloud-amd64
linux-image-4.15.0-0.bpo.2-amd64 - Linux 4.15 for 64-bit PCs
linux-image-4.15.0-0.bpo.2-amd64-dbg - Debug symbols for linux-image-4.15.0-0.bpo.2-amd64
linux-image-4.15.0-0.bpo.2-cloud-amd64 - Linux 4.15 for x86-64 cloud
linux-image-4.15.0-0.bpo.2-cloud-amd64-dbg - Debug symbols for linux-image-4.15.0-0.bpo.2-cloud-amd64
linux-image-4.16.0-0.bpo.1-amd64 - Linux 4.16 for 64-bit PCs
linux-image-4.16.0-0.bpo.1-amd64-dbg - Debug symbols for linux-image-4.16.0-0.bpo.1-amd64
linux-image-4.16.0-0.bpo.1-cloud-amd64 - Linux 4.16 for x86-64 cloud
linux-image-4.16.0-0.bpo.1-cloud-amd64-dbg - Debug symbols for linux-image-4.16.0-0.bpo.1-cloud-amd64
linux-headers-4.9.0-4-grsec-amd64 - Header files for Linux 4.9.0-4-grsec-amd64
linux-image-4.9.0-4-grsec-amd64 - Linux 4.9 for 64-bit PCs, Grsecurity protection (unofficial patch)
linux-image-grsec-amd64 - Linux image meta-package, grsec featureset
linux-image-cloud-amd64 - Linux for x86-64 cloud (meta-package)
linux-image-cloud-amd64-dbg - Debugging symbols for Linux cloud-amd64 configuration (meta-package)
Run Code Online (Sandbox Code Playgroud)

我也需要标题。在 Ubuntu 上也有名为extra或类似的包,所以我很困惑没有在这里看到它。


在 Debian 9 上手动安装新内核的正确方法是什么?

kem*_*tep 13

手头问题

您需要比 Debian 实例上安装的内核更新的 Linux 内核。有一定的风险这一点。建议您避免偏离 Debian 提供的默认稳定 LTS 内核。但是,由于您的需要,您需要更新的内核。

解决方案

您可以添加backports 存储库,使用 apt-pinning 控制此处安装的内容,并安装必要的组件来升级您的内核。

我强烈推荐apt-pinning,因为您可以添加备用存储库甚至第三方存储库并控制从它们安装的内容。这允许您再次自行承担风险,安装和更新替代软件包和库,并与操作系统的主要组件一起更新它们。Apt-pinning 允许对来自替代来源(即不稳定)的包装进行精细控制,并具有较低的破损风险。如果你理解了风险,你可以用这个前进。

添加反向移植库和设置的apt-偏好

第一步是正确的库添加到您的sources.list。我建议您使用,/sources.list.d/但您可以仅在一个文件中执行此操作。

#Main Stable Repo
deb http://deb.debian.org stable main contrib non-free 
deb-src http://deb.debian.org stable main contrib non-free
#Stable-updates
deb http://deb.debian.org stable-updates main contrib non-free 
deb-src http://deb.debian.org stable-updates main contrib non-free 
#Security Updates 
deb http://deb.debian.org/debian-secruity stable/updates main contrib non-free
deb-src http://deb.debian.org/debian-secruity stable/updates main contrib non-free 
#Stretch Backports    
deb http://ftp.debian.org/debian stretch-backports main contrib non-free
deb-src http://ftp.debian.org/debian stretch-backports main contrib non-free
Run Code Online (Sandbox Code Playgroud)

sources.list应该是这个样子。如果您不需要非自由软件,则不需要非自由部分。接下来,您将需要使用给封装引脚的优先级/etc/apt/preferences。这个文件应该是这样的:

Package: *
Pin: release a=debian-security
Pin-Priority: 1000

Package: *
Pin: release a=stable
Pin-Priority: 900

Package: *
Pin: release a=stable-updates
Pin-Priority: 800

Package: *
Pin: release a=stretch-backports
Pin-Priority: 700
Run Code Online (Sandbox Code Playgroud)

您可以更精细地指定单个封装,并为引脚优先级分配更高或更低的值。

在此之后运行apt-get update

安装所需内核

使用apt-cache search linux-image你会列出所有可用的内核。当您确定了您想要的内核后,您可以使用apt-get install linux-image-flavour. 建议您也安装匹配的 Linux 头文件包。如果您的环境中需要 grsec 映像,请安装该映像。再次用适当的头包为好。

重新启动后,您将能够在 GRUB 菜单中选择要启动的内核。如果您遇到问题,您始终可以选择已知良好的内核,然后使用该内核进行引导。

结论

我已经使用 apt-pinning 成功管理了我个人计算机的 Debian 安装。我使用上述方法安装了当时(4.15)的最新内核,并且我的系统运行良好。但是,请注意这一点,因为它是一台个人计算机,而不是我认为是您希望在其上安装它的生产服务器。我还包括指向我引用的所有来源的链接。我使用这个Debian Wiki 页面来告知必要的步骤,以及apt-pinning页面。这篇文章也被引用了。

如果您对这篇文章有任何疑问或疑虑,请随时问我。如果此答案中有任何更正或误解,请通知我。我可以根据需要更新帖子。

祝你好运!


tel*_*coM 10

如果要安装较新的 Debian 打包内核,则应使用 backports 存储库中的内核。您似乎已经将该存储库添加到您的apt配置中,因此您已准备就绪。

由于您当前的内核是基本的 amd64 版本,我假设您不需要实时调度程序版本,也不需要云版本。

赶紧跑

apt-get install linux-image-4.16.0-0.bpo.1-amd64 linux-headers-4.16.0-0.bpo.1-amd64
Run Code Online (Sandbox Code Playgroud)

即“安装为 Debian 9 反向移植的 4.16 内核的基本 -amd64 版本,以及相应的头文件包”。

与常规软件包不同,新版本linux-image软件包不会完全替换现有的 4.9.0 内核,而是会与其一起安装。(这是因为版本号作为包名称的一部分包含在内。)引导加载程序将在linux-image安装后自动配置为以基于版本号的顺序显示可用内核,或者如果某些引导加载程序不可能,只需将最近安装的自动设置为首选。

如果事实证明您的新内核无法启动,您只需从引导加载程序中选择以前的内核,然后删除被证明不起作用的内核包。如果你不小心告诉包管理器删除你当前正在运行的内核,它很聪明地知道这不是一件好事,并且会中止操作。