# 1. 獲取源碼
cd /home
wget https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.15.100.tar.xz
tar -xJf linux-5.15.100.tar.xz -C /usr/src
cd /usr/src
ln -sf linux-5.15.100 linux
cd linux
# 2. 配置
make mrproper # 清理 (非首次編譯必須)
make menuconfig # 或 make olddefconfig 升級舊配置
# 3. 編譯 (30-60 分鐘視 CPU 核心數)
make -j$(nproc) bzImage
make -j$(nproc) modules
make modules_install # 安裝模組至 /lib/modules/5.15.100/
make install # 安裝核心至 /boot、更新 GRUB、生成 initramfs
# 單一指令生成二進位與原始碼 RPM
make rpm
# 或指定版本資訊
make rpm-pkg KDEB_PKGVERSION=5.15.100-1.custom
輸出位置:
/usr/src/rpm/RPMS/x86_64/kernel-5.15.100-1.custom.x86_64.rpm (舊路徑 /usr/src/redhat/RPMS/)/usr/src/rpm/SRPMS/kernel-5.15.100-1.custom.src.rpm
rpm -ivh kernel-5.15.100-1.custom.x86_64.rpm
# 自動:安裝 /boot/vmlinuz-*, /lib/modules/*, System.map, 更新 GRUB 配置
# 手動:生成 initramfs (若未自動)
dracut -f /boot/initramfs-5.15.100-1.custom.img 5.15.100-1.custom
# 或舊版
mkinitrd /boot/initramfs-5.15.100-1.custom.img 5.15.100-1.custom
rpm -Uvh kernel-5.15.100-1.custom.src.rpm
rpmbuild -bp --target=$(arch) /usr/src/rpm/SPECS/kernel.spec
cd /usr/src/rpm/BUILD/kernel-5.15.100-1.custom
# 修改 Makefile EXTRAVERSION 避免衝突
cp /boot/config-$(uname -r) .config
make menuconfig
# 繼續標準編譯流程 (make bzImage modules modules_install install)
make bindeb-pkg (需 kernel-rpm-macros) 或 copr 建構服務。podman run --rm -v $(pwd):/src -w /src kernel-build-env make rpm 隔離建構環境。make mrproper 清理乾淨,避免舊 .config/.o 殘留干擾。CONFIG_LOCALVERSION 設定唯一後綴 (如 -custom),避免與發布版核心衝突。/lib/modules/$(uname -r)/ 必須與核心版本完全對應。