LKU:一套在 Ubuntu/LinuxMint 上编译、安装和更新最新内核的 Shell 脚本
创始人
2024-03-01 20:16:25
0

以手动方式安装和升级最新的 Linux 内核对于每个人来说都不是一件小事,甚至包括一些有经验的人也是如此。它需要对 Linux 内核有深入的了解。过去我们已经介绍了 UKUU(Ubuntu Kernel Upgrade Utility),它可以从 kernel.ubuntu.com 网站上自动检测最新的主线内核,并弹出一个不错的窗口界面进行安装。

Linux Kernel Utilities (LKU)提供一组 shell 脚本(三个 Shell 脚本),可以帮助用户从 kernel.org 获取并编译和安装最新的 Linux 内核,也可以从 kernel.ubuntu.com 获取安装最新的预编译的 Ubuntu 内核。甚至可以根据需要选择所需的内核(手动内核选择)。

该脚本还将根据 PGP 签名文件检查下载的归档文件,并且可以选择通用和低延迟版内核。

建议阅读:ukuu:一种在基于 Ubuntu 的系统上轻松安装升级 Linux 内核的方式

它可以删除或清除所有非活动的内核,并且不会为了安全目的留下备份的内核。强烈建议在执行此脚本之前重新启动一次。

  • compile_linux_kernel.sh :用户可以从 kernel.org 编译和安装所需的或最新的内核
  • update_ubuntu_kernel.sh :用户可以从 kernel.ubuntu.com 安装并更新所需或最新的预编译 Ubuntu 内核
  • remove_old_kernels.sh :这将删除或清除所有非活动内核,并且只保留当前加载的版本

kernel.org 有固定的发布周期(每三个月一次),发布的内核包括了新的功能,改进了硬件和系统性能。由于它具有标准的发布周期,除了滚动发布的版本(如 Arch Linux,openSUSE Tumbleweed 等),大多数发行版都不提供最新的内核。

如何安装 Linux Kernel Utilities (LKU)

正如我们在文章的开头所说的,它的 shell 脚本集只是克隆开发人员的 github 仓库并运行相应的 shell 文件来执行这个过程。

$ git clone https://github.com/mtompkins/linux-kernel-utilities.git && cd linux-kernel-utilities

安装指定版本内核

为了测试的目的,我们将安装 Linux v4.4.10-xenial 内核。在安装新内核之前,我们需要通过 uanme -a 命令检查当前安装的内核版本,以便我们可以检查新内核是否可以安装。

$ uname -a
Linux magi-VirtualBox 4.4.0-21-generic #37-Ubuntu SMP Mon Apr 18 18:33:37 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

根据上面的输出,我们的系统使用的是 4.4.0-21 通用内核。

只需运行 update_ubuntu_kernel.sh shell 脚本。第一次运行脚本时会检查是否满足所有的依赖关系,然后自动安装缺少的依赖项。它会检测系统使用的发行版,并检索 kernel.ubuntu.com 中可用的预编译内核。现在,从列表中选择你需要的内核并输入序号,然后按回车键,它将下载内核映像(linux-headers-4.4.10,linux-headers-4.4.10-xxx-generic 和 linux-image-4.4.10-xxx-generic)。

一旦内核镜像被下载,它将要求输入 sudo 密码来启动新内核的安装。

$ ./update_ubuntu_kernel.sh

[+] Checking Distro
 \_ Distro identified as LinuxMint.

[+] Checking Dependencies
    curl                    Found
    dkms                    Found
    git                     Found
    sudo                    Found
    wget                    Found
    whiptail                Found
    lynx                    Not Found

-- Installing Dependencies --

[!] The first time this script is run missing dependencies will be installed.
    For compiling a kernel this may take a bit of time. Feedback will be provided.

[+] Dependencies
 \_Elevating permissions as necessary . . .
[%] Elevated

[+] Testing for previous held packages and trying to correct any found.
 \_Passed

[+] Updating package cache . . .
 \_Complete

[+] Installing dependencies . . .
 \_Complete

    curl                    Found
    dkms                    Found
    git                     Found
    sudo                    Found
    wget                    Found
    whiptail                Found
    lynx                    Found

[+] Changing to temporary directory to work in . . .
 \_ Temporary directory access granted: /tmp/tmp.97eHDsmg2K

[+] Removing any conflicting remnants . . .
 \_ Done

[+] Retrieving available kernel choices . . .
 \_ Precompiled kernels available from kernel.ubuntu.com:

 1)  Linux v4.11                2)  Linux v4.11.3              3)  Linux v4.11.2              4)  Linux v4.11.1             
 5)  Linux v4.10                6)  Linux v4.10.17             7)  Linux v4.10.16             8)  Linux v4.10.15            
 9)  Linux v4.10.14             10) Linux v4.10.13             11) Linux v4.10.12
[ 节略 ……]                     
 249) Linux v4.0.3-wily          250) Linux v4.0.2-wily          251) Linux v4.0.1-wily          252) Linux v4.0-vivid          

Select your desired kernel: 158

Do you want the lowlatency kernel? (y/[n]):

[+] Processing selection
 \_ Determining CPU type: amd64
 \_ Locating source of v4.4.10-xenial generic kernel packages.
 \_ Done

[+] Checking AntiVirus flag and disabling if necessary
[+] Installing kernel . . .
[sudo] password for magi:
Selecting previously unselected package linux-headers-4.4.10-040410.
(Reading database ... 230647 files and directories currently installed.)
Preparing to unpack linux-headers-4.4.10-040410_4.4.10-040410.201605110631_all.deb ...
Unpacking linux-headers-4.4.10-040410 (4.4.10-040410.201605110631) ...
Selecting previously unselected package linux-headers-4.4.10-040410-generic.
Preparing to unpack linux-headers-4.4.10-040410-generic_4.4.10-040410.201605110631_amd64.deb ...
Unpacking linux-headers-4.4.10-040410-generic (4.4.10-040410.201605110631) ...
Selecting previously unselected package linux-image-4.4.10-040410-generic.
Preparing to unpack linux-image-4.4.10-040410-generic_4.4.10-040410.201605110631_amd64.deb ...
Done.
Unpacking linux-image-4.4.10-040410-generic (4.4.10-040410.201605110631) ...
Setting up linux-headers-4.4.10-040410 (4.4.10-040410.201605110631) ...
Setting up linux-headers-4.4.10-040410-generic (4.4.10-040410.201605110631) ...
Examining /etc/kernel/header_postinst.d.
run-parts: executing /etc/kernel/header_postinst.d/dkms 4.4.10-040410-generic /boot/vmlinuz-4.4.10-040410-generic
Setting up linux-image-4.4.10-040410-generic (4.4.10-040410.201605110631) ...
Running depmod.
update-initramfs: deferring update (hook will be called later)
Examining /etc/kernel/postinst.d.
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.4.10-040410-generic /boot/vmlinuz-4.4.10-040410-generic
run-parts: executing /etc/kernel/postinst.d/dkms 4.4.10-040410-generic /boot/vmlinuz-4.4.10-040410-generic
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.4.10-040410-generic /boot/vmlinuz-4.4.10-040410-generic
update-initramfs: Generating /boot/initrd.img-4.4.10-040410-generic
Warning: No support for locale: en_IN
run-parts: executing /etc/kernel/postinst.d/pm-utils 4.4.10-040410-generic /boot/vmlinuz-4.4.10-040410-generic
run-parts: executing /etc/kernel/postinst.d/unattended-upgrades 4.4.10-040410-generic /boot/vmlinuz-4.4.10-040410-generic
run-parts: executing /etc/kernel/postinst.d/zz-update-grub 4.4.10-040410-generic /boot/vmlinuz-4.4.10-040410-generic
Generating grub configuration file ...
Warning: Setting GRUB_TIMEOUT to a non-zero value when GRUB_HIDDEN_TIMEOUT is set is no longer supported.
Found linux image: /boot/vmlinuz-4.4.10-040410-generic
Found initrd image: /boot/initrd.img-4.4.10-040410-generic
Found linux image: /boot/vmlinuz-4.4.9-040409-lowlatency
Found initrd image: /boot/initrd.img-4.4.9-040409-lowlatency
Found linux image: /boot/vmlinuz-4.4.0-21-generic
Found initrd image: /boot/initrd.img-4.4.0-21-generic
Found memtest86+ image: /boot/memtest86+.elf
Found memtest86+ image: /boot/memtest86+.bin
done
 \_ Done

安装后需要重新启动以使用新安装的内核。

$ sudo reboot now

现在,你正在使用的就是新安装的 4.4.10-040410-generic 版本内核。

$ uname -a
Linux magi-VirtualBox 4.4.10-040410-generic #201605110631 SMP Wed May 11 10:33:23 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

安装最新版本内核

过程与上述相同,它将自动安装最新版本的内核。

$ ./update_ubuntu_kernel.sh --latest

[+] Checking Distro
 \_ Distro identified as LinuxMint.

[+] Checking Dependencies
    curl                    Found
    dkms                    Found
    git                     Found
    sudo                    Found
    wget                    Found
    whiptail                Found
    lynx                    Found

[+] Changing to temporary directory to work in . . .
 \_ Temporary directory access granted: /tmp/tmp.pLPYmCze6S

[+] Removing any conflicting remnants . . .
 \_ Done

[+] Retrieving available kernel choices . . .
 \_ Precompiled kernels available from kernel.ubuntu.com:
.
.
.
.
Warning: Setting GRUB_TIMEOUT to a non-zero value when GRUB_HIDDEN_TIMEOUT is set is no longer supported.
Found linux image: /boot/vmlinuz-4.11.3-041103-generic
Found initrd image: /boot/initrd.img-4.11.3-041103-generic
Found linux image: /boot/vmlinuz-4.4.10-040410-generic
Found initrd image: /boot/initrd.img-4.4.10-040410-generic
Found linux image: /boot/vmlinuz-4.4.9-040409-lowlatency
Found initrd image: /boot/initrd.img-4.4.9-040409-lowlatency
Found linux image: /boot/vmlinuz-4.4.0-21-generic
Found initrd image: /boot/initrd.img-4.4.0-21-generic
Found memtest86+ image: /boot/memtest86+.elf
Found memtest86+ image: /boot/memtest86+.bin
done
 \_ Done

安装后需要重新启动以使用新安装的内核。

$ sudo reboot now

现在,你正在使用的就是最新版本 4.11.3-041103-generic 的内核。

$ uname -a
Linux magi-VirtualBox 4.11.3-041103-generic #201705251233 SMP Thu May 25 16:34:52 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

删除或清除旧内核

只需要运行 remove_old_kernels.sh shell 脚本即可删除或清除所有非活动状态的内核。

$ ./remove_old_kernels.sh

        ++++++++++++++++++++++++++++++++
        +++       W A R N I N G      +++
        ++++++++++++++++++++++++++++++++

A reboot is recommended before running this script to ensure the current kernel tagged
as the boot kernel is indeed registered and old kernels properly marked for removal.
If you have just installed or modified your existing kernel and do not reboot before
running this script it may render you system INOPERABLE and that would indeed suck.

You have been warned.
~the Mgmt

[?]Continue to automagically remove ALL old kernels? (y/N)y
\_ Removing ALL old kernels . . .
[sudo] password for magi:
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  linux-headers-4.4.0-21* linux-headers-4.4.0-21-generic* linux-headers-4.4.10-040410*
  linux-headers-4.4.10-040410-generic* linux-headers-4.4.9-040409* linux-headers-4.4.9-040409-lowlatency*
  linux-image-4.4.0-21-generic* linux-image-4.4.10-040410-generic* linux-image-4.4.9-040409-lowlatency*
  linux-image-extra-4.4.0-21-generic* linux-kernel-generic*
0 upgraded, 0 newly installed, 11 to remove and 547 not upgraded.
After this operation, 864 MB disk space will be freed.
(Reading database ... 296860 files and directories currently installed.)
Removing linux-kernel-generic (4.4.0-21) ...
Removing linux-headers-4.4.0-21-generic (4.4.0-21.37) ...
Removing linux-headers-4.4.0-21 (4.4.0-21.37) ...
Removing linux-headers-4.4.10-040410-generic (4.4.10-040410.201605110631) ...
Removing linux-headers-4.4.10-040410 (4.4.10-040410.201605110631) ...
Removing linux-headers-4.4.9-040409-lowlatency (4.4.9-040409.201605041832) ...
Removing linux-headers-4.4.9-040409 (4.4.9-040409.201605041832) ...
Removing linux-image-extra-4.4.0-21-generic (4.4.0-21.37) ...
.
.
.
done
Purging configuration files for linux-image-4.4.9-040409-lowlatency (4.4.9-040409.201605041832) ...
Examining /etc/kernel/postrm.d .
run-parts: executing /etc/kernel/postrm.d/initramfs-tools 4.4.9-040409-lowlatency /boot/vmlinuz-4.4.9-040409-lowlatency
run-parts: executing /etc/kernel/postrm.d/zz-update-grub 4.4.9-040409-lowlatency /boot/vmlinuz-4.4.9-040409-lowlatency

via: http://www.2daygeek.com/lku-linux-kernel-utilities-compile-install-update-latest-kernel-in-linux-mint-ubuntu/

作者:2DAYGEEK 译者:firmianay 校对:wxy

本文由 LCTT 原创编译,Linux中国 荣誉推出

相关内容

AI视频大战升级:Sora...
本报(chinatimes.net.cn)记者于玉金 北京报道 从...
2025-06-28 22:43:19
不设薪酬上限!京东打响互联...
每经记者|王郁彪 每经编辑|文多 据报道,Meta首席执行官马克...
2025-06-28 12:42:46
“AI+教育”再提速 科大...
6月24日,科大讯飞举办AI学习机2025暑期发布会。本次发布会以...
2025-06-25 11:11:02
AI换脸、跨平台引流 反诈...
“‘客服’能准确报出我身份证前几位,还催着要银行卡号……”6月10...
2025-06-17 09:41:24
滴滴企业版“AI+一站式”...
6月10日,在上海举办的企业出行服务峰会上,针对差旅流程割裂、体验...
2025-06-11 14:43:15
海信宣布:开源66项三筒洗...
当技术从“护城河”变成“铺路石”,当竞争从“零和博弈”转向“生态共...
2025-06-03 13:10:45

热门资讯

Helix:高级 Linux ... 说到 基于终端的文本编辑器,通常 Vim、Emacs 和 Nano 受到了关注。这并不意味着没有其他...
使用 KRAWL 扫描 Kub... 用 KRAWL 脚本来识别 Kubernetes Pod 和容器中的错误。当你使用 Kubernet...
JStock:Linux 上不... 如果你在股票市场做投资,那么你可能非常清楚投资组合管理计划有多重要。管理投资组合的目标是依据你能承受...
通过 SaltStack 管理... 我在搜索Puppet的替代品时,偶然间碰到了Salt。我喜欢puppet,但是我又爱上Salt了:)...
Epic 游戏商店现在可在 S... 现在可以在 Steam Deck 上运行 Epic 游戏商店了,几乎无懈可击! 但是,它是非官方的。...
《Apex 英雄》正式可在 S... 《Apex 英雄》现已通过 Steam Deck 验证,这使其成为支持 Linux 的顶级多人游戏之...
如何在 Github 上创建一... 学习如何复刻一个仓库,进行更改,并要求维护人员审查并合并它。你知道如何使用 git 了,你有一个 G...
2024 开年,LLUG 和你... Hi,Linuxer,2024 新年伊始,不知道你是否已经准备好迎接新的一年~ 2024 年,Lin...
什么是 KDE Connect... 什么是 KDE Connect?它的主要特性是什么?它应该如何安装?本文提供了基本的使用指南。科技日...
Opera 浏览器内置的 VP... 昨天我们报道过 Opera 浏览器内置了 VPN 服务,用户打开它可以防止他们的在线活动被窥视。不过...