You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何编译安装带特定名称的多版本Linux内核及对应模块

编译带/不带调试符号的Linux内核并分离安装

以下是针对内核6.0.7的完整操作命令集,实现两个版本(带调试符号/无调试符号)的分离安装:

前置准备

确保已安装编译依赖(以Debian/Ubuntu为例):

sudo apt install build-essential libncurses-dev bison flex libssl-dev libelf-dev

下载并解压内核6.0.7源码到~/linux-6.0.7目录(若已有则跳过):

wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.0.7.tar.xz
tar -xf linux-6.0.7.tar.xz
cd ~/linux-6.0.7

第一步:编译无调试符号版本(nodebug)

  1. 清理编译痕迹,导入当前系统内核配置:
make distclean
cp /boot/config-$(uname -r) .config
  1. 关闭调试符号配置:
scripts/config --disable DEBUG_INFO
# 若需彻底关闭所有调试相关选项,可额外执行:
# scripts/config --disable DEBUG_INFO_DWARF4
# scripts/config --disable DEBUG_INFO_REDUCED
  1. 编译内核及模块(-j$(nproc)用全部CPU核心加速):
make -j$(nproc)
  1. 安装模块到/lib/modules/nodebug:
sudo make INSTALL_MOD_DIR=nodebug modules_install
  1. 手动复制内核镜像到/boot(避免覆盖其他版本):
sudo cp vmlinux /boot/vmlinux-6.0.7
sudo cp arch/x86/boot/bzImage /boot/vmlinuz-6.0.7
  1. 生成对应initramfs(以Debian/Ubuntu为例):
sudo update-initramfs -c -k 6.0.7

第二步:编译带调试符号版本(debug)

  1. 回到源码目录,清理之前的编译痕迹:
cd ~/linux-6.0.7
make distclean
cp /boot/config-$(uname -r) .config
  1. 开启调试符号配置(可选用DWARF5格式提升调试体验):
scripts/config --enable DEBUG_INFO
scripts/config --set-val DEBUG_INFO_DWARF5 y
  1. 编译内核及模块:
make -j$(nproc)
  1. 安装模块到/lib/modules/debug:
sudo make INSTALL_MOD_DIR=debug modules_install
  1. 手动复制带调试符号的内核镜像到/boot:
sudo cp vmlinux /boot/vmlinux-6.0.7-debug
sudo cp arch/x86/boot/bzImage /boot/vmlinuz-6.0.7-debug
  1. 生成对应initramfs:
sudo update-initramfs -c -k 6.0.7-debug

第三步:更新启动引导菜单

更新GRUB配置,让两个内核版本出现在启动选项中:

sudo update-grub

(若为Arch Linux,执行sudo grub-mkconfig -o /boot/grub/grub.cfg)


关键说明

  • 使用INSTALL_MOD_DIR而非INSTALL_DIR/INSTALL_MOD_PATH:该参数直接指定模块在/lib/modules下的目录名,完美匹配需求
  • 手动复制镜像而非make install:避免make install自动覆盖同名内核文件,确保两个版本独立存在
  • 调试符号版本的vmlinux体积会远大于无调试版本,属于正常现象

内容的提问来源于stack exchange,提问作者Alberto

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 03:25:30