LKU:一套在Ubuntu/LinuxMint上编译、安装和更新最新内核的Shell脚本

以手动方式安装和升级最新的 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 文件来执行这个过程。


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

安装指定版本内核

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


  1. $ uname -a 
  2. 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 密码来启动新内核的安装。


  1. $ ./update_ubuntu_kernel.sh 
  2. [+] Checking Distro 
  3.  \_ Distro identified as LinuxMint. 
  4. [+] Checking Dependencies 
  5.     curl                    Found 
  6.     dkms                    Found 
  7.     git                     Found 
  8.     sudo                    Found 
  9.     wget                    Found 
  10.     whiptail                Found 
  11.     lynx                    Not Found 
  12. -- Installing Dependencies -- 
  13. [!] The first time this script is run missing dependencies will be installed. 
  14.     For compiling a kernel this may take a bit of time. Feedback will be provided. 
  15. [+] Dependencies 
  16.  \_Elevating permissions as necessary . . . 
  17. [%] Elevated 
  18. [+] Testing for previous held packages and trying to correct any found. 
  19.  \_Passed 
  20. [+] Updating package cache . . . 
  21.  \_Complete 
  22. [+] Installing dependencies . . . 
  23.  \_Complete 
  24.     curl                    Found 
  25.     dkms                    Found 
  26.     git                     Found 
  27.     sudo                    Found 
  28.     wget                    Found 
  29.     whiptail                Found 
  30.     lynx                    Found 
  31. [+] Changing to temporary directory to work in . . . 
  32.  \_ Temporary directory access granted: /tmp/tmp.97eHDsmg2K 
  33. [+] Removing any conflicting remnants . . . 
  34.  \_ Done 
  35. [+] Retrieving available kernel choices . . . 
  36.  \_ Precompiled kernels available from kernel.ubuntu.com: 
  37.  1)  Linux v4.11                2)  Linux v4.11.3              3)  Linux v4.11.2              4)  Linux v4.11.1              
  38.  5)  Linux v4.10                6)  Linux v4.10.17             7)  Linux v4.10.16             8)  Linux v4.10.15             
  39.  9)  Linux v4.10.14             10) Linux v4.10.13             11) Linux v4.10.12 
  40. [ 节略 ……]                      
  41.  249) Linux v4.0.3-wily          250) Linux v4.0.2-wily          251) Linux v4.0.1-wily          252) Linux v4.0-vivid           
  42. Select your desired kernel: 158 
  43. Do you want the lowlatency kernel? (y/[n]): 
  44. [+] Processing selection 
  45.  \_ Determining CPU type: amd64 
  46.  \_ Locating source of v4.4.10-xenial generic kernel packages. 
  47.  \_ Done 
  48. [+] Checking AntiVirus flag and disabling if necessary 
  49. [+] Installing kernel . . . 
  50. [sudo] password for magi: 
  51. Selecting previously unselected package linux-headers-4.4.10-040410. 
  52. (Reading database ... 230647 files and directories currently installed.) 
  53. Preparing to unpack linux-headers-4.4.10-040410_4.4.10-040410.201605110631_all.deb ... 
  54. Unpacking linux-headers-4.4.10-040410 (4.4.10-040410.201605110631) ... 
  55. Selecting previously unselected package linux-headers-4.4.10-040410-generic. 
  56. Preparing to unpack linux-headers-4.4.10-040410-generic_4.4.10-040410.201605110631_amd64.deb ... 
  57. Unpacking linux-headers-4.4.10-040410-generic (4.4.10-040410.201605110631) ... 
  58. Selecting previously unselected package linux-image-4.4.10-040410-generic. 
  59. Preparing to unpack linux-image-4.4.10-040410-generic_4.4.10-040410.201605110631_amd64.deb ... 
  60. Done. 
  61. Unpacking linux-image-4.4.10-040410-generic (4.4.10-040410.201605110631) ... 
  62. Setting up linux-headers-4.4.10-040410 (4.4.10-040410.201605110631) ... 
  63. Setting up linux-headers-4.4.10-040410-generic (4.4.10-040410.201605110631) ... 
  64. Examining /etc/kernel/header_postinst.d. 
  65. run-parts: executing /etc/kernel/header_postinst.d/dkms 4.4.10-040410-generic /boot/vmlinuz-4.4.10-040410-generic 
  66. Setting up linux-image-4.4.10-040410-generic (4.4.10-040410.201605110631) ... 
  67. Running depmod. 
  68. update-initramfs: deferring update (hook will be called later) 
  69. Examining /etc/kernel/postinst.d. 
  70. run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.4.10-040410-generic /boot/vmlinuz-4.4.10-040410-generic 
  71. run-parts: executing /etc/kernel/postinst.d/dkms 4.4.10-040410-generic /boot/vmlinuz-4.4.10-040410-generic 
  72. run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.4.10-040410-generic /boot/vmlinuz-4.4.10-040410-generic 
  73. update-initramfs: Generating /boot/initrd.img-4.4.10-040410-generic 
  74. Warning: No support for locale: en_IN 
  75. run-parts: executing /etc/kernel/postinst.d/pm-utils 4.4.10-040410-generic /boot/vmlinuz-4.4.10-040410-generic 
  76. run-parts: executing /etc/kernel/postinst.d/unattended-upgrades 4.4.10-040410-generic /boot/vmlinuz-4.4.10-040410-generic 
  77. run-parts: executing /etc/kernel/postinst.d/zz-update-grub 4.4.10-040410-generic /boot/vmlinuz-4.4.10-040410-generic 
  78. Generating grub configuration file ... 
  79. Warning: Setting GRUB_TIMEOUT to a non-zero value when GRUB_HIDDEN_TIMEOUT is set is no longer supported. 
  80. Found linux image: /boot/vmlinuz-4.4.10-040410-generic 
  81. Found initrd image: /boot/initrd.img-4.4.10-040410-generic 
  82. Found linux image: /boot/vmlinuz-4.4.9-040409-lowlatency 
  83. Found initrd image: /boot/initrd.img-4.4.9-040409-lowlatency 
  84. Found linux image: /boot/vmlinuz-4.4.0-21-generic 
  85. Found initrd image: /boot/initrd.img-4.4.0-21-generic 
  86. Found memtest86+ image: /boot/memtest86+.elf 
  87. Found memtest86+ image: /boot/memtest86+.bin 
  88. done 
  89.  \_ Done 

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


  1. $ sudo reboot now 

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


  1. $ uname -a 
  2. 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 

安装最新版本内核

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


  1. $ ./update_ubuntu_kernel.sh --latest 
  2. [+] Checking Distro 
  3.  \_ Distro identified as LinuxMint. 
  4. [+] Checking Dependencies 
  5.     curl                    Found 
  6.     dkms                    Found 
  7.     git                     Found 
  8.     sudo                    Found 
  9.     wget                    Found 
  10.     whiptail                Found 
  11.     lynx                    Found 
  12. [+] Changing to temporary directory to work in . . . 
  13.  \_ Temporary directory access granted: /tmp/tmp.pLPYmCze6S 
  14. [+] Removing any conflicting remnants . . . 
  15.  \_ Done 
  16. [+] Retrieving available kernel choices . . . 
  17.  \_ Precompiled kernels available from kernel.ubuntu.com: 
  18. Warning: Setting GRUB_TIMEOUT to a non-zero value when GRUB_HIDDEN_TIMEOUT is set is no longer supported. 
  19. Found linux image: /boot/vmlinuz-4.11.3-041103-generic 
  20. Found initrd image: /boot/initrd.img-4.11.3-041103-generic 
  21. Found linux image: /boot/vmlinuz-4.4.10-040410-generic 
  22. Found initrd image: /boot/initrd.img-4.4.10-040410-generic 
  23. Found linux image: /boot/vmlinuz-4.4.9-040409-lowlatency 
  24. Found initrd image: /boot/initrd.img-4.4.9-040409-lowlatency 
  25. Found linux image: /boot/vmlinuz-4.4.0-21-generic 
  26. Found initrd image: /boot/initrd.img-4.4.0-21-generic 
  27. Found memtest86+ image: /boot/memtest86+.elf 
  28. Found memtest86+ image: /boot/memtest86+.bin 
  29. done 
  30.  \_ Done 

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


  1. $ sudo reboot now 

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


  1. $ uname -a 
  2. 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 脚本即可删除或清除所有非活动状态的内核。


  1. $ ./remove_old_kernels.sh 
  2.         ++++++++++++++++++++++++++++++++ 
  3.         +++       W A R N I N G      +++ 
  4.         ++++++++++++++++++++++++++++++++ 
  5. A reboot is recommended before running this script to ensure the current kernel tagged 
  6. as the boot kernel is indeed registered and old kernels properly marked for removal. 
  7. If you have just installed or modified your existing kernel and do not reboot before 
  8. running this script it may render you system INOPERABLE and that would indeed suck. 
  9. You have been warned. 
  10. ~the Mgmt 
  11. [?]Continue to automagically remove ALL old kernels? (y/N)y 
  12. \_ Removing ALL old kernels . . . 
  13. [sudo] password for magi: 
  14. Reading package lists... Done 
  15. Building dependency tree        
  16. Reading state information... Done 
  17. The following packages will be REMOVED: 
  18.   linux-headers-4.4.0-21* linux-headers-4.4.0-21-generic* linux-headers-4.4.10-040410* 
  19.   linux-headers-4.4.10-040410-generic* linux-headers-4.4.9-040409* linux-headers-4.4.9-040409-lowlatency* 
  20.   linux-image-4.4.0-21-generic* linux-image-4.4.10-040410-generic* linux-image-4.4.9-040409-lowlatency* 
  21.   linux-image-extra-4.4.0-21-generic* linux-kernel-generic* 
  22. 0 upgraded, 0 newly installed, 11 to remove and 547 not upgraded. 
  23. After this operation, 864 MB disk space will be freed. 
  24. (Reading database ... 296860 files and directories currently installed.) 
  25. Removing linux-kernel-generic (4.4.0-21) ... 
  26. Removing linux-headers-4.4.0-21-generic (4.4.0-21.37) ... 
  27. Removing linux-headers-4.4.0-21 (4.4.0-21.37) ... 
  28. Removing linux-headers-4.4.10-040410-generic (4.4.10-040410.201605110631) ... 
  29. Removing linux-headers-4.4.10-040410 (4.4.10-040410.201605110631) ... 
  30. Removing linux-headers-4.4.9-040409-lowlatency (4.4.9-040409.201605041832) ... 
  31. Removing linux-headers-4.4.9-040409 (4.4.9-040409.201605041832) ... 
  32. Removing linux-image-extra-4.4.0-21-generic (4.4.0-21.37) ... 
  33. done 
  34. Purging configuration files for linux-image-4.4.9-040409-lowlatency (4.4.9-040409.201605041832) ... 
  35. Examining /etc/kernel/postrm.d . 
  36. run-parts: executing /etc/kernel/postrm.d/initramfs-tools 4.4.9-040409-lowlatency /boot/vmlinuz-4.4.9-040409-lowlatency 
  37. run-parts: executing /etc/kernel/postrm.d/zz-update-grub 4.4.9-040409-lowlatency /boot/vmlinuz-4.4.9-040409-lowlatency 

作者:2daygeek

来源:51CTO

时间: 2024-08-22 14:59:40

LKU:一套在Ubuntu/LinuxMint上编译、安装和更新最新内核的Shell脚本的相关文章

CentOS 6.7 x64上编译安装ffmpeg的教程

系统信息 [root@LookBack ~]# getconf LONG_BIT 64 [root@LookBack ~]# cat /etc/redhat-release CentOS release 6.7 (Final) yum源信息,这里就不再说epel和rpmforge源的安装了 [root@LookBack ~]# yum repolist 已加载插件:fastestmirror Loading mirror speeds from cached hostfile  * base:

Ubuntu下nginx编译安装参数配置_nginx

安装依赖库: sudo apt-get install libgd2-xpm sudo apt-get install libgd2-xpm-dev sudo apt-get install libgeoip-dev sudo apt-get install libpcre3 sudo apt-get install libpcre3-dev sudo apt-get install libssl-dev sudo apt-get install openssl sudo apt-get ins

在Ubuntu X64上编译Hadoop

在之前的文章中介绍了如何直接在Ubuntu中安装Hadoop.但是对于64位的Ubuntu来说,官方给出的Hadoop包是32位的,运行时会得到警告: WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable 所以我们最好是自己在Ubuntu中编译Hadoop.先介绍一下我的环境是Ubuntu 1

ubuntu 13.10编译安装mono环境(二)_Linux

准备工作 先在VS2012上编译一个winform,代码如下: using System; using System.Windows.Forms; namespace FormsTest { static class Program { /// <summary> /// 应用程序的主入口点. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.S

PHP7 学习笔记(一)Ubuntu 16.04 编译安装Nginx-1.10.3、 PHP7.0.9、Redis3.0 扩展、Phalcon3.1 扩展、Swoole1.9.8 扩展、ssh2扩展(全程编译安装)

 ==================== PHP 7.0 编译安装================== wget http://cn2.php.net/get/php-7.0.9.tar.bz2/from/this/mirror -- 下载php镜像tar xvf mirror -- 解压镜像cd php-7.0.9/ -- 进入安装目录sudo apt-get update -- 更新阿里云库 sudo apt-get install libkrb5-dev \ libc-client200

CentOS上编译安装Nginx环境步骤

一.安装前准备 1.获取系统信息  代码如下 复制代码 # cat /etc/redhat-release CentOS release 6.5 (Final) # uname -p x86_64 由上可知,当前系统:64位CentOS 6.5. 2.安装基础包  代码如下 复制代码 # yum install gcc # yum install wget 二.安装Nginx模块基础库 1.安装HTTP rewrite(伪静态)模块需要的PCRE库.  代码如下 复制代码 # yum insta

在 Debian 和 Ubuntu 系统上自动安装安全更新

之前已经说过,一些最优秀的系统管理员看上去(注意这里使用的词是 seem(看上去))总是很"懒"的,这句话我再同意不过了. 虽然这句话听起来有点荒谬,但我敢打赌在大多数情况下它是对的-不是因为他们不去做他们原本应该做的事情,而是因为他们已经让系统自动去完成这样的事情了. 对于 Linux 系统来说,一个最关键的需求是为相应的 Linux 版本保持更新最新的安全补丁. 在这篇文章中,我们将讨论如何在 Debian 和 Ubuntu 系统上进行设置,从而实现自动安装或更新重要的安装包或补丁

如何在 Debian 和 Ubuntu 系统上自动安装安全更新

之前已经说过,一些最优秀的系统管理员看上去(注意这里使用的词是 seem(看上去))总是很"懒"的,这句话我再同意不过了. 虽然这句话听起来有点荒谬,但我敢打赌在大多数情况下它是对的-不是因为他们不去做他们原本应该做的事情,而是因为他们已经让系统自动去完成这样的事情了. 对于 Linux 系统来说,一个最关键的需求是为相应的 Linux 版本保持更新最新的安全补丁. 在这篇文章中,我们将讨论如何在 Debian 和 Ubuntu 系统上进行设置,从而实现自动安装或更新重要的安装包或补丁

Ubuntu10.04上编译安装部署Mono2.10.8+Nginx1.0.11+MySQL5.5.20实战

上一篇关于mono的是将一个小的系统移植体验,这次折腾了4天把这个小的系统部署到线上(国外的vps).vps上安装了Ubuntu10.04的服务器版本,意味着是非常纯净的.而我又想都用最新版的环境,所以几乎全部编译安装mono2.10.8 Nginx1.0.11 MySQL5.5.20.现在把折腾的过程跟大家分享下,希望给那些对mono充满好感的朋友一点帮助,我折腾过了,希望大家不用再折腾了,而是比较顺利的完成整个过程. 一,准备工作 执行sudo apt-get install build-e