# 清理舊建構產物 (非首次編譯必須)
sudo make mrproper
# 參考當前運行核心配置 (Debian/Ubuntu 已自動複製,手動亦可)
cp /boot/config-$(uname -r) .config
# 或使用 make olddefconfig 自動遷移
| 指令 | 介面 | 適用場景 |
|---|---|---|
make config | 逐行文字詢問 | 極少用,腳本自動化 |
make menuconfig | ncurses 選單 (終端機) | 推薦,SSH/本地終端機通用 |
make xconfig | Qt 圖形介面 | 桌面環境,需 Qt 庫 |
make gconfig | GTK 圖形介面 | GNOME 桌面 |
make oldconfig | 僅詢問新選項 | 核心小版本升級 |
make defconfig | 架構預設配置 | 全新起步基線 |
make allnoconfig | 全關閉 (最小) | 嵌入式/極精簡 |
lspci -nnk
# 輸出範例:
00:1f.2 SATA controller [0106]: Intel Corporation 82801IBM/IEM (ICH9M-E/M) SATA Controller [AHCI mode] [8086:2929]
Kernel driver in use: ahci
Kernel modules: ahci
02:00.0 Ethernet controller [0200]: Realtek RTL8111/8168/8411 [10ec:8168]
Kernel driver in use: r8169
Kernel modules: r8169
[8086:2929] = VendorID:DeviceID,精確匹配驅動。Kernel driver in use:當前載入驅動模組名。Kernel modules:可用模組名 (配置時搜尋此字串)。
File systems →
[*] Ext4 filesystem support (CONFIG_EXT4_FS=y)
[*] Ext4 POSIX ACLs
[*] Ext4 Security Labels
# 若用 Ext3:
[*] Ext3 journalling file system support (CONFIG_EXT3_FS=y)
# 若用 XFS/Btrfs 同理設為 Y
鐵律:根分區檔案系統驅動必須內建核心 (Y),設為模組 (M) 會導致 pivot_root: pivot_root(/sysroot,/sysroot/initrd) failed 或 switch_root 失敗,因 initramfs 階段無法載入模組。
Device Drivers → Serial ATA (SATA) support →
[*] AHCI SATA support (CONFIG_SATA_AHCI=y) # 現代 Intel/AMD 主流
[*] Intel PIIX/ICH SATA support (CONFIG_ATA_PIIX=y) # 較舊 Intel
Device Drivers → SCSI device support → SCSI low-level drivers →
[*] LSI Logic MegaRAID SAS (CONFIG_MEGARAID_SAS=y) # 伺服器 RAID 卡
[*] VMware PVSCSI (CONFIG_VMWARE_PVSCSI=y) # 虛擬機
Device Drivers → Network device support → Ethernet driver support →
[*] Realtek 8169/8168/8101/8125/8161/8162/8168/8169 PCIe (CONFIG_R8169=y)
[*] Intel PRO/1000 (e1000e) (CONFIG_E1000E=y)
# 虛擬機常用:
[*] Virtio network driver (CONFIG_VIRTIO_NET=y)
# 1. 依賴關係 (2.6+ 可省略)
# make dep
# 2. 清理舊物件 (確保乾淨)
make clean
# 3. 編譯核心映像 (壓縮)
make -j$(nproc) bzImage
# 大核心自動選用 bzImage (支援 >512KB),zImage 限制較小
# 4. 編譯模組
make -j$(nproc) modules
# 5. 安裝模組至系統標準位置
sudo make modules_install
# → /lib/modules/5.15.100-custom/
# 6. 安裝核心、System.map、更新 GRUB、生成 initramfs
sudo make install
# 內部執行:cp arch/x86/boot/bzImage /boot/vmlinuz-
# cp System.map /boot/System.map-
# /sbin/installkernel /boot/vmlinuz- /boot/System.map-
# → 觸發 initramfs 生成 + GRUB 更新
make INSTALL_MOD_PATH=/target/rootfs modules_install
# 模組安裝至 /target/rootfs/lib/modules//
make install 透過 /etc/kernel/install.d/ 腳本自動:
/boot/grub/grub.cfg 新增菜單項。update-initramfs -c -k 生成 initramfs。手動檢查:
grep -A5 "menuentry.*" /boot/grub/grub.cfg
ls -l /boot/initrd.img- /boot/vmlinuz-
Device Drivers → Sound card support →
[*] Advanced Linux Sound Architecture (CONFIG_SND=y)
[*] Sequencer support (CONFIG_SND_SEQUENCER=y)
[*] OSS Mixer/PCM/Sequencer API (相容層)
[*] RTC Timer support (CONFIG_SND_RTCTIMER=y)
PCI devices →
[*] Intel HD Audio (CONFIG_SND_HDA_INTEL=y)
[*] Build Realtek HD-audio codec support (CONFIG_SND_HDA_CODEC_REALTEK=y)
[*] Build Analog Devices HD-audio codec support (CONFIG_SND_HDA_CODEC_ANALOG=y)
現代系統統一使用 ALSA (CONFIG_SND),OSS 為相容層。