linux升级降级内核实验
✅实验环境
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
设置默认内核
重启验证内核