?實驗環境
vmware workstation 17?
centos7.9
下載鏈接:
https://vault.centos.org/7.9.2009/isos/x86_64/
ubuntu24.04
?下載鏈接:
https://old-releases.ubuntu.com/releases/24.04/
?實驗目的
為了解決日常環境部署中某些驅動軟件依賴特定內核版本,此教程實驗,用于內核版本的調整實驗,針對于主流的linux,做出升級,降級的實驗詳細步驟。
?內核升級的方式
🧩 一、Ubuntu升級內核的 4 種方式對比
升級方式 | 適用場景 | 優點 | 缺點 |
---|---|---|---|
1?? 使用官方倉庫 apt 升級 | 生產環境 | 穩定、安全 | 版本略舊 |
2?? 安裝 Mainline 主線內核 | 新硬件支持/新功能測試 | 最新內核 | 不自動更新,風險稍高 |
3?? 手動安裝 .deb 內核包 | 安裝特定版本內核 | 靈活 | 易配置錯誤 |
4?? 從源碼編譯內核 | 自定義裁剪、優化 | 可完全控制內核 | 復雜,耗時多 |
🧩 二、CentOS 內核升級方式總覽
方式 | 說明 | 是否推薦 |
---|---|---|
1?? 使用官方倉庫升級內核(默認內核流) | 安全穩定,適合生產 | ? 推薦 |
2?? 啟用 ELRepo 安裝最新長期支持內核(LTS) | 獲取更高版本 | ? 推薦 |
3?? 編譯安裝內核源碼 | 高度定制,靈活 | ?? 高級用戶 |
4?? 手動下載 .rpm 安裝主線內核 | 測試、臨時用途 | ?? 有風險 |
5?? 升級為 CentOS Stream 或 RHEL 最新版 | 跟隨官方 rolling | 可選 |
?Ubuntu24.04內核升級降級
初始安裝內核信息如下
admin1@test1:~$ uname -a
Linux test1 6.8.0-31-generic #31-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 20 00:40:06 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
admin1@test1:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 24.04 LTS
Release: 24.04
Codename: noble
admin1@test1:~$
🧩apt方式升級到6.14
?查找可用的內核包
命令如下
sudo apt-cache search linux-image
admin1@test1:~$
admin1@test1:~$ sudo apt update
admin1@test1:~$ sudo apt-cache search linux-image
admin1@test1:~$ sudo apt-cache search linux-image | grep 6.14
linux-image-6.14.0-1004-oem - Signed kernel image oem
linux-image-6.14.0-1005-nvidia - Signed kernel image nvidia
linux-image-6.14.0-1005-oem - Signed kernel image oem
linux-image-6.14.0-1007-aws - Signed kernel image aws
linux-image-6.14.0-1007-gcp - Signed kernel image gcp
linux-image-6.14.0-1007-oracle - Signed kernel image oracle
linux-image-aws-6.14 - Linux kernel image for Amazon Web Services (AWS) systems.
linux-image-nvidia-6.14 - NVIDIA Linux kernel image
linux-image-uc-6.14.0-1004-oem - Signed kernel image oem for Ubuntu Core
linux-image-uc-6.14.0-1005-oem - Signed kernel image oem for Ubuntu Core
linux-image-uc-6.14.0-1007-aws - Signed kernel image aws for Ubuntu Core
linux-image-uc-aws-6.14 - AWS Linux kernel image for Ubuntu Core
linux-image-unsigned-6.14.0-1004-oem - Linux kernel image for version 6.14.0
linux-image-unsigned-6.14.0-1005-nvidia - Linux kernel image for version 6.14.0
linux-image-unsigned-6.14.0-1005-oem - Linux kernel image for version 6.14.0
linux-image-unsigned-6.14.0-1007-aws - Linux kernel image for version 6.14.0 on DESC
linux-image-unsigned-6.14.0-1007-gcp - Linux kernel image for version 6.14.0 on DESC
linux-image-unsigned-6.14.0-1007-oracle - Oracle Linux kernel image for version 6.14.0 on DESC
admin1@test1:~$
?開始安裝
查詢到有更新的6.14 版本內核,開始執行升級
命令如下:
sudo apt-get install linux-image-6.14.0-1005 linux-headers-6.14.0-1005 linux-modules-6.14.0-1005
admin1@test1:~$ sudo apt-get install linux-image-6.14.0-1005 linux-headers-6.14.0-1005 linux-modules-6.14.0-1005
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Note, selecting 'linux-image-6.14.0-1005-oem' for regex 'linux-image-6.14.0-1005'
Note, selecting 'linux-image-6.14.0-1005-nvidia' for regex 'linux-image-6.14.0-1005'
Note, selecting 'linux-headers-6.14.0-1005-nvidia' for regex 'linux-headers-6.14.0-1005'
Note, selecting 'linux-headers-6.14.0-1005-oem' for regex 'linux-headers-6.14.0-1005'
Note, selecting 'linux-modules-6.14.0-1005-nvidia' for regex 'linux-modules-6.14.0-1005'
Note, selecting 'linux-modules-6.14.0-1005-oem' for regex 'linux-modules-6.14.0-1005'
The following additional packages will be installed:linux-nvidia-6.14-headers-6.14.0-1005 linux-oem-6.14-headers-6.14.0-1005
Suggested packages:linux-perf linux-nvidia-6.14-tools linux-modules-extra-6.14.0-1005-nvidia fdutils linux-oem-6.14-tools
The following NEW packages will be installed:linux-headers-6.14.0-1005-nvidia linux-headers-6.14.0-1005-oem linux-image-6.14.0-1005-nvidia linux-image-6.14.0-1005-oem linux-modules-6.14.0-1005-nvidialinux-modules-6.14.0-1005-oem linux-nvidia-6.14-headers-6.14.0-1005 linux-oem-6.14-headers-6.14.0-1005
0 upgraded, 8 newly installed, 0 to remove and 312 not upgraded.
Need to get 268 MB of archives.
After this operation, 468 MB of additional disk space will be used.
Do you want to continue? [Y/n]
............................................................
............................
Adding boot menu entry for UEFI Firmware Settings ...
done
Processing triggers for linux-image-6.14.0-1005-nvidia (6.14.0-1005.5) ...
/etc/kernel/postinst.d/initramfs-tools:
update-initramfs: Generating /boot/initrd.img-6.14.0-1005-nvidia
/etc/kernel/postinst.d/zz-update-grub:
Sourcing file `/etc/default/grub'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-6.14.0-1005-oem
Found initrd image: /boot/initrd.img-6.14.0-1005-oem
Found linux image: /boot/vmlinuz-6.14.0-1005-nvidia
Found initrd image: /boot/initrd.img-6.14.0-1005-nvidia
Found linux image: /boot/vmlinuz-6.8.0-31-generic
Found initrd image: /boot/initrd.img-6.8.0-31-generic
Warning: os-prober will not be executed to detect other bootable partitions.
Systems on them will not be added to the GRUB boot configuration.
Check GRUB_DISABLE_OS_PROBER documentation entry.
Adding boot menu entry for UEFI Firmware Settings ...
done
Scanning processes...
Scanning linux images... Pending kernel upgrade!
Running kernel version:6.8.0-31-generic
Diagnostics:The currently running kernel version is not the expected kernel version 6.14.0-1005-oem.Restarting the system to load the new kernel will not be handled automatically, so you should consider rebooting.No services need to be restarted.No containers need to be restarted.No user sessions are running outdated binaries.No VM guests are running outdated hypervisor (qemu) binaries on this host.
? 查看GRUB 菜單
執行安裝完畢,apt會自動設置為新的默認內核啟動不用修改默認引導內核,直接重啟驗證
? 重啟后驗證
admin1@test1:~$ uname -a
Linux test1 6.14.0-1005-oem #5-Ubuntu SMP PREEMPT_DYNAMIC Mon Jun 2 06:47:26 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
admin1@test1:~$
🧩安裝 Mainline 主線內核(降級6.1)
? PPA 安裝Mainline
Mainline 依賴于 mainline 工具,需要從 PPA 安裝
sudo add-apt-repository ppa:cappelikan/ppa -y
sudo apt update
sudo apt install mainline -y
執行步驟如下
admin1@test1:~$ sudo add-apt-repository ppa:cappelikan/ppa -y
[sudo] password for admin1:
Repository: 'Types: deb
URIs: https://ppa.launchpadcontent.net/cappelikan/ppa/ubuntu/
Suites: noble
Components: main
'
Description:
Mainline Ubuntu Kernel Installer https://github.com/bkw777/mainline
More info: https://launchpad.net/~cappelikan/+archive/ubuntu/ppa
Adding repository.
Hit:1 http://security.ubuntu.com/ubuntu noble-security InRelease
Get:5 https://ppa.launchpadcontent.net/cappelikan/ppa/ubuntu noble InRelease [17.8 kB]
Get:6 https://ppa.launchpadcontent.net/cappelikan/ppa/ubuntu noble/main amd64 Packages [592 B]
Get:7 https://ppa.launchpadcontent.net/cappelikan/ppa/ubuntu noble/main Translation-en [316 B]
Hit:2 http://mirrors.tuna.tsinghua.edu.cn/ubuntu noble InRelease
Hit:3 http://mirrors.tuna.tsinghua.edu.cn/ubuntu noble-updates InRelease
Hit:4 http://mirrors.tuna.tsinghua.edu.cn/ubuntu noble-backports InRelease
Fetched 18.7 kB in 6s (3034 B/s)
Reading package lists... Done
admin1@test1:~$ sudo apt update
Hit:4 https://ppa.launchpadcontent.net/cappelikan/ppa/ubuntu noble InRelease
Hit:1 http://mirrors.tuna.tsinghua.edu.cn/ubuntu noble InRelease
Hit:2 http://mirrors.tuna.tsinghua.edu.cn/ubuntu noble-updates InRelease
Hit:3 http://mirrors.tuna.tsinghua.edu.cn/ubuntu noble-backports InRelease
Hit:5 http://security.ubuntu.com/ubuntu noble-security InRelease
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
250 packages can be upgraded. Run 'apt list --upgradable' to see them.
admin1@test1:~$ sudo apt install mainline -y
? 執行mainline list查詢內核
admin1@test1:~$ mainline list
mainline 1.4.13
Updating Kernels...
----------------------------------------------------------------
Available Kernels
----------------------------------------------------------------
6.15.4
6.15.2
6.15.1
6.15
6.14.11
6.14.10
6.14.8
6.14.7
6.14.6
6.14.4
6.14.3
6.14.2
6.14.1
6.14.0-1005.5_nvidia Installed
6.14.0-1005.5_oem Running
6.14
6.13.12
6.13.11
6.13.10
6.13.9
6.13.8
6.13.7
6.13.6
6.13.5
6.13.4
..............................................
..........................
6.1.128
6.1.127
6.1.126
6.1.125
6.1.119
6.1.110
6.1.105
6.1.100
6.1.95
6.1.85
6.1.80
6.1.70
6.1.25
6.1.20
6.1.15
6.1.10
6.1
6.0.19
6.0.18
6.0.17
6.0.16
6.0.15
6.0.14
6.0.13
6.0.12
6.0.11
6.0.10
6.0.5
6.0
mainline: done
admin1@test1:~$
? 執行安裝內核
admin1@test1:~$ sudo mainline install 6.1
mainline 1.4.13
Updating Kernels...
Downloading 6.1
Installing 6.1
sh: 1: pkexec: not found
mainline: done
admin1@test1:~$
?報錯信息解決
提示sh: 1: pkexec: not found ,執行
sudo apt install -y pkexec
pkexec --version
重新執行內核安裝
admin1@test1:~$ sudo mainline install 6.1
mainline 1.4.13
Updating Kernels...
Downloading 6.1
Installing 6.1
Selecting previously unselected package linux-modules-6.1.0-060100-generic.
(Reading database ... 206503 files and directories currently installed.)
Preparing to unpack .../linux-modules-6.1.0-060100-generic_6.1.0-060100.202303090726_amd64.deb ...
Unpacking linux-modules-6.1.0-060100-generic (6.1.0-060100.202303090726) ...
Selecting previously unselected package linux-headers-6.1.0-060100.
Preparing to unpack .../linux-headers-6.1.0-060100_6.1.0-060100.202303090726_all.deb ...
Unpacking linux-headers-6.1.0-060100 (6.1.0-060100.202303090726) ...
Selecting previously unselected package linux-headers-6.1.0-060100-generic.
Preparing to unpack .../linux-headers-6.1.0-060100-generic_6.1.0-060100.202303090726_amd64.deb ...
Unpacking linux-headers-6.1.0-060100-generic (6.1.0-060100.202303090726) ...
Selecting previously unselected package linux-image-unsigned-6.1.0-060100-generic.
Preparing to unpack .../linux-image-unsigned-6.1.0-060100-generic_6.1.0-060100.202303090726_amd64.deb ...
Unpacking linux-image-unsigned-6.1.0-060100-generic (6.1.0-060100.202303090726) ...
Setting up linux-modules-6.1.0-060100-generic (6.1.0-060100.202303090726) ...
Setting up linux-headers-6.1.0-060100 (6.1.0-060100.202303090726) ...
Setting up linux-headers-6.1.0-060100-generic (6.1.0-060100.202303090726) ...
Setting up linux-image-unsigned-6.1.0-060100-generic (6.1.0-060100.202303090726) ...
I: /boot/vmlinuz.old is now a symlink to vmlinuz-6.8.0-63-generic
I: /boot/initrd.img.old is now a symlink to initrd.img-6.8.0-63-generic
I: /boot/vmlinuz is now a symlink to vmlinuz-6.1.0-060100-generic
I: /boot/initrd.img is now a symlink to initrd.img-6.1.0-060100-generic
Processing triggers for linux-image-unsigned-6.1.0-060100-generic (6.1.0-060100.202303090726) ...
/etc/kernel/postinst.d/initramfs-tools:
update-initramfs: Generating /boot/initrd.img-6.1.0-060100-generic
/etc/kernel/postinst.d/zz-update-grub:
Sourcing file `/etc/default/grub'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-6.14.0-1005-oem
Found initrd image: /boot/initrd.img-6.14.0-1005-oem
Found linux image: /boot/vmlinuz-6.14.0-1005-nvidia
Found initrd image: /boot/initrd.img-6.14.0-1005-nvidia
Found linux image: /boot/vmlinuz-6.8.0-63-generic
Found initrd image: /boot/initrd.img-6.8.0-63-generic
Found linux image: /boot/vmlinuz-6.8.0-31-generic
Found initrd image: /boot/initrd.img-6.8.0-31-generic
Found linux image: /boot/vmlinuz-6.1.0-060100-generic
Found initrd image: /boot/initrd.img-6.1.0-060100-generic
Warning: os-prober will not be executed to detect other bootable partitions.
Systems on them will not be added to the GRUB boot configuration.
Check GRUB_DISABLE_OS_PROBER documentation entry.
Adding boot menu entry for UEFI Firmware Settings ...
done
mainline: done
admin1@test1:~$
?更改引導內核的順序
查看配置文件,6.1不是首位引導,需要更改引導內核的順序
編輯默認引導grub文件,設置6.1為第一引導
sudo vi /etc/default/grub,修改首行配置信息如下
GRUB_DEFAULT="Ubuntu, with Linux 6.1.0-060100-generic"
執行?sudo update-grub,如設置不合規,會提示你正確的配置方法,
admin1@test1:~$ sudo update-grub
Sourcing file `/etc/default/grub'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-6.14.0-1005-oem
Found initrd image: /boot/initrd.img-6.14.0-1005-oem
Found linux image: /boot/vmlinuz-6.14.0-1005-nvidia
Found initrd image: /boot/initrd.img-6.14.0-1005-nvidia
Found linux image: /boot/vmlinuz-6.8.0-63-generic
Found initrd image: /boot/initrd.img-6.8.0-63-generic
Found linux image: /boot/vmlinuz-6.8.0-31-generic
Found initrd image: /boot/initrd.img-6.8.0-31-generic
Found linux image: /boot/vmlinuz-6.1.0-060100-generic
Found initrd image: /boot/initrd.img-6.1.0-060100-generic
Warning: Please don't use old title `Ubuntu, with Linux 6.1.0-060100-generic' for GRUB_DEFAULT, use `Advanced options for Ubuntu>Ubuntu, with Linux 6.1.0-060100-generic' (for versions before 2.00) or `gnulinux-advanced-341f26c0-2016-4b44-a8af-062d13f2ce6d>gnulinux-6.1.0-060100-generic-advanced-341f26c0-2016-4b44-a8af-062d13f2ce6d' (for 2.00 or later)
Warning: os-prober will not be executed to detect other bootable partitions.
Systems on them will not be added to the GRUB boot configuration.
Check GRUB_DISABLE_OS_PROBER documentation entry.
Adding boot menu entry for UEFI Firmware Settings ...
done
admin1@test1:~$
根據如下警告,復制正確的設置方法,
Warning: Please don't use old title `Ubuntu, with Linux 6.1.0-060100-generic' for GRUB_DEFAULT, use `Advanced options for Ubuntu>Ubuntu, with Linux 6.1.0-060100-generic' (for versions before 2.00) or `gnulinux-advanced-341f26c0-2016-4b44-a8af-062d13f2ce6d>gnulinux-6.1.0-060100-generic-advanced-341f26c0-2016-4b44-a8af-062d13f2ce6d' (for 2.00 or later)
重新編輯 /etc/default/grub文件,執行sudo update-grub?
GRUB_DEFAULT="Advanced options for Ubuntu>Ubuntu, with Linux 6.1.0-060100-generic"
dmin1@test1:~$ sudo update-grub
Sourcing file `/etc/default/grub'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-6.14.0-1005-oem
Found initrd image: /boot/initrd.img-6.14.0-1005-oem
Found linux image: /boot/vmlinuz-6.14.0-1005-nvidia
Found initrd image: /boot/initrd.img-6.14.0-1005-nvidia
Found linux image: /boot/vmlinuz-6.8.0-63-generic
Found initrd image: /boot/initrd.img-6.8.0-63-generic
Found linux image: /boot/vmlinuz-6.8.0-31-generic
Found initrd image: /boot/initrd.img-6.8.0-31-generic
Found linux image: /boot/vmlinuz-6.1.0-060100-generic
Found initrd image: /boot/initrd.img-6.1.0-060100-generic
Warning: os-prober will not be executed to detect other bootable partitions.
Systems on them will not be added to the GRUB boot configuration.
Check GRUB_DISABLE_OS_PROBER documentation entry.
Adding boot menu entry for UEFI Firmware Settings ...
done
admin1@test1:~$
?重啟驗證
admin1@test1:~$ uname -a
Linux test1 6.1.0-060100-generic #202303090726 SMP PREEMPT_DYNAMIC Thu Mar 9 12:33:28 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
admin1@test1:~$
🧩手動安裝deb包升級
?內核下載網站
https://kernel.ubuntu.com/mainline/
下載5.19 包,進行降級處理,下載包
wget https://kernel.ubuntu.com/mainline/v5.19/amd64/linux-headers-5.19.0-051900-generic_5.19.0-051900.202207312230_amd64.deb
wget https://kernel.ubuntu.com/mainline/v5.19/amd64/linux-headers-5.19.0-051900_5.19.0-051900.202207312230_all.deb
wget https://kernel.ubuntu.com/mainline/v5.19/amd64/linux-image-unsigned-5.19.0-051900-generic_5.19.0-051900.202207312230_amd64.deb
wget https://kernel.ubuntu.com/mainline/v5.19/amd64/linux-modules-5.19.0-051900-generic_5.19.0-051900.202207312230_amd64.deb
?執行安裝
admin1@test1:~$ ls -lh
total 115M
-rw-rw-r-- 1 admin1 admin1 3.1M Jul 31 2022 linux-headers-5.19.0-051900-generic_5.19.0-051900.202207312230_amd64.deb
-rw-rw-r-- 1 admin1 admin1 12M Jul 31 2022 linux-headers-5.19.0-051900_5.19.0-051900.202207312230_all.deb
-rw-rw-r-- 1 admin1 admin1 12M Jul 31 2022 linux-image-unsigned-5.19.0-051900-generic_5.19.0-051900.202207312230_amd64.deb
-rw-rw-r-- 1 admin1 admin1 88M Jul 31 2022 linux-modules-5.19.0-051900-generic_5.19.0-051900.202207312230_amd64.deb
admin1@test1:~$ sudo dpkg -i linux-*
?更改內核啟動順序,重啟后驗證
修改/etc/default/grub文件內容如下
GRUB_DEFAULT="Advanced options for Ubuntu>Ubuntu, with Linux 5.19.0-051900-generic"
admin1@test1:~$ uname -a
Linux test1 5.19.0-051900-generic #202207312230 SMP PREEMPT_DYNAMIC Sun Jul 31 22:34:11 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
admin1@test1:~$
🧩源碼編譯安裝升級
? 準備工作
1?? 安裝必備工具和依賴:
sudo apt install -y build-essential libncurses-dev bison flex libssl-dev libelf-dev libncurses5-dev
? 獲取內核源碼
https://www.kernel.org/
這里下載的是6.15.4
wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.15.4.tar.xz
解壓xz包
tar -xvf linux-6.15.4.tar.xz
? 配置內核
cp /boot/config-$(uname -r) .config
??快速方式(使用默認配置)
make olddefconfig
??交互配置(高級用戶)
make menuconfig
需修改配置,保存并退出(保存到 .config)
驗證
admin1@test1:~/linux-6.15.4$ cat .config | grep CONFIG_BONDING
CONFIG_BONDING=m
admin1@test1:~/linux-6.15.4$
預期輸出:CONFIG_BONDING=m(模塊形式)
? 編譯內核
make -j$(nproc)
這將編譯內核映像(bzImage)和模塊。
耗時取決于硬件,可能需要 30 分鐘至幾小時。
編譯報錯
ake[3]: *** No rule to make target 'debian/canonical-certs.pem', needed by 'certs/x509_certificate_list'. Stop
?錯誤成因簡述:
Ubuntu 系統的 /boot/config-*
默認啟用了如下配置項:
dmin1@test1:~/linux-6.15.4$ grep "CONFIG_SYSTEM_TRUSTED_KEYS" .config
CONFIG_SYSTEM_TRUSTED_KEYS="debian/canonical-certs.pem"
admin1@test1:~/linux-6.15.4$ grep "CONFIG_SYSTEM_REVOCATION_KEYS" .config
CONFIG_SYSTEM_REVOCATION_KEYS="debian/canonical-revoked-certs.pem"
admin1@test1:~/linux-6.15.4$
它告訴編譯系統去找 debian/canonical-certs.pem
文件作為簽名證書來源。但你是從 kernel.org 下載的內核源碼,這個文件自然不存在,導致編譯失敗。
編譯系統去找 debian/canonical-certs.pem
文件作為簽名證書來源
解決方法:修改.config文件如下
CONFIG_SYSTEM_TRUSTED_KEYS=""
CONFIG_SYSTEM_REVOCATION_KEYS=""
或者使用sed命令如下:
sed -i 's/CONFIG_SYSTEM_REVOCATION_KEYS=.*/CONFIG_SYSTEM_REVOCATION_KEYS=""/' .config
sed -i 's/CONFIG_SYSTEM_TRUSTED_KEYS=.*/CONFIG_SYSTEM_TRUSTED_KEYS=""/' .config
? 然后重新編譯:
make -j$(nproc)
sudo make modules_install
sudo make install
sudo update-grub
執行步驟如下
? 結果驗證
執行以下命令查看是否仍引用該文件:
grep canonical .config
應無內容或為空值。
確認新內核出現在 GRUB 菜單中:
cat /boot/grub/grub.cfg | grep 6.14
設置默認內核
重啟驗證內核