下载内核
Linux Kernel 的官方网站https://www.kernel.org

编译安装环境
更新
apt update
apt upgrade
安装编译所需的软件包
apt install build-essential libncurses5-dev gcc libssl-dev bc libelf-dev flex bison rsync
下载压缩包
wget https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.18.tar.xz
解压进入目录
tar xvf linux-5.18.tar.xz
cd linux-5.18
复制配置文件
现在我们必须将引导配置复制到“linux-5.18”目录中。我们这样做是因为要弄清楚要启用什么内核模块,要禁用什么才能获得一个正常工作的系统,需要做很多工作。所以我们可以只使用当前内核正在使用的配置。
新内核可能有很多旧内核没有的新特性。因此,最好运行以下命令将旧配置文件转换为新配置文件。否则我们会被问到很多对您来说可能没有意义的问题。
root@debian:~# cp /boot/config-$(uname -r) .config
'/boot/config-5.10.0-14-cloud-amd64' -> '.config/config-5.10.0-14-cloud-amd64'
编辑配置
make menuconfig
您将看到以下窗口。从这里您可以启用和禁用特定的内核功能。如果您不知道在此处做什么,请保留默认值。

选择 Save 保存退出
开始编译
我的 VPS 是2CPU 所以使用 -j 2
选项
make -j 2 deb-pkg
报错

make[2]: *** [debian/rules:7: build-arch] Error 2
dpkg-buildpackage: error: debian/rules binary subprocess returned exit status 2
make[1]: *** [scripts/Makefile.package:77: deb-pkg] Error 2
make: *** [Makefile:1542: deb-pkg] Error 2
解决方法: 编辑linux-5.18
目录下.config

CONFIG_SYSTEM_TRUSTED_KEYS="debian/certs/debian-uefi-certs.pem" # 找到
CONFIG_SYSTEM_TRUSTED_KEYS="" # 改为空值
编译完成
完成后root目录下 有3个deb包

安装deb包
dpkg -i ./linux-*.deb

查看当前安装的内核,已经有5.18的了
dpkg --list | grep linux-image

更新grub2配置
update-grub2
重启 reboot
内核启动成功变成5.18了

删除旧内核,再更新下grub2配置
dpkg --list | grep linux-image
apt remove --purge linux-image-5.10.0-13-amd64
apt autoremove
apt autoclean
update-grub2
参考文章:
https://linuxhint.com/how-to-upgrade-kernel-of-debian-9-stretch-from-source/
https://gitlab.com/CalcProgrammer1/OpenRGB/-/issues/950
https://askubuntu.com/questions/1245882/kernel-make-menuconfig-error