當前位置:
首頁 > 知識 > LKU:一套在 Ubuntu/LinuxMint 上編譯、安裝和更新最新內核的 Shell 腳本

LKU:一套在 Ubuntu/LinuxMint 上編譯、安裝和更新最新內核的 Shell 腳本

LKU:一套在 Ubuntu/LinuxMint 上編譯、安裝和更新最新內核的 Shell 腳本


以手動方式安裝和升級最新的 Linux 內核對於每個人來說都不是一件小事,甚至包括一些有經驗的人也是如此。它需要對 Linux 內核有深入的了解。 -- 2daygeek

本文導航

  • -如何安裝 Linux Kernel Utilities (LKU) …… 15%

  • -安裝指定版本內核 …… 17%

  • -安裝最新版本內核 …… 64%

  • -刪除或清除舊內核 …… 78%

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

作者: 2daygeek

譯者: firmianay

以手動方式安裝和升級最新的 Linux 內核對於每個人來說都不是一件小事,甚至包括一些有經驗的人也是如此。它需要對 Linux 內核有深入的了解。過去我們已經介紹了 UKUU(Ubuntu Kernel Upgrade Utility),它可以從 kernel.ubuntu.com 網站上自動檢測最新的主線內核,並彈出一個不錯的窗口界面進行安裝。

Linux Kernel Utilities[1] (LKU)提供一組 shell 腳本(三個 Shell 腳本),可以幫助用戶從 kernel.org 獲取並編譯和安裝最新的 Linux 內核,也可以從 kernel.ubuntu.com 獲取安裝最新的預編譯的 Ubuntu 內核。甚至可以根據需要選擇所需的內核(手動內核選擇)。

該腳本還將根據 PGP 簽名文件檢查下載的歸檔文件,並且可以選擇通用和低延遲版內核。

建議閱讀:ukuu:一種在基於 Ubuntu 的系統上輕鬆安裝升級 Linux 內核的方式[2]

它可以刪除或清除所有非活動的內核,並且不會為了安全目的留下備份的內核。強烈建議在執行此腳本之前重新啟動一次。

  • 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[3] 譯者:firmianay 校對:wxy

本文由 LCTT 原創編譯,Linux中國 榮譽推出

  • [1]: Linux Kernel Utilities - https://github.com/mtompkins/linux-kernel-utilities

  • [2]: ukuu:一種在基於 Ubuntu 的系統上輕鬆安裝升級 Linux 內核的方式 - http://www.2daygeek.com/ukuu-install-upgrade-linux-kernel-in-linux-mint-ubuntu-debian-elementary-os/

  • [3]: 2DAYGEEK - http://www.2daygeek.com/author/2daygeek/

喜歡這篇文章嗎?立刻分享出去讓更多人知道吧!

本站內容充實豐富,博大精深,小編精選每日熱門資訊,隨時更新,點擊「搶先收到最新資訊」瀏覽吧!


請您繼續閱讀更多來自 Linux技術 的精彩文章:

深度學習(Deep Learning)發展史
在 Ubuntu 16.04 中使用 Docker Compose
使用統一阻止列表和白名單來更新主機文件
使用開源代碼構建機器人時需要考慮的事項

TAG:Linux技術 |

您可能感興趣

在Kali Linux上安裝PowerShell
在 VirtualBox 上安裝 Kali Linux 的最安全快捷的方式
UKTools:安裝最新 Linux 內核的簡便方法
如何在Windows 10上安裝Ubuntu或openSUSE
怎樣在 Ubuntu Linux 上安裝 MySQL
把玩Alpine linux(四):安裝zsh和docker
經典Wind95系統變APP,可在Windows、macOS、Linux安裝使用
Ubuntu Docker 安裝
Skype的Snap安裝包發布,Microsoft Loves Linux
Ubuntu Linux環境下shadowsocks-qt5的安裝與配置
在Windows 10的Linux子系統中安裝完整版kali
ASDK系列2:在Azure新的Region上安裝部署Azure Stack開發工具包的第二種方法
追月,Linux雲伺服器編譯安裝最新Apache、PHP和MySQL
Chromium和Firefox擁抱Snap格式 可安裝在Ubuntu等發行版本
把玩Alpine linux(一):安裝
Linux下安裝Tomcat
MAC上基於VirtualEnv安裝TensorFlow
在Red Hat和Centos上安裝MongoDB
如何在 Linux 中安裝、配置和使用 Fish Shell?
Linux Memcached 安裝