Why would someone want to compile a new kernel? It is often not necessary since the default kernel shipped with Debian handles most configurations. Also, Debian often offers several alternative kernels. So you may want to check first if there is an alternative kernel image package that better corresponds to your hardware. However, it can be useful to compile a new kernel in order to:
支援某些特殊的硬體,或者預設的核心設定和某些硬體衝突。
use options of the kernel which are not supported in the pre-supplied kernels (such as high memory support)
透過刪除無用的驅動程式來優化核心,以減少開機時間。
create a monolithic instead of a modularized kernel
使用最新的核心或開發中的核心。
learn more about linux kernels
不要害怕嘗試編譯核心。它很有趣而且很有好處。
To compile a kernel the Debian way, you need some packages: fakeroot, kernel-package, linux-source-2.6 and a few others which are probably already installed (see /usr/share/doc/kernel-package/README.gz for the complete list).
此方法將從您的核心原始碼建立一個 .deb 檔案,並且,如果您有非標準模組,將同時建立它們的同步相依 .deb 檔案。這是一個管理核心的較好的方法﹔/boot 目錄將保存核心,System.map,以及目前編譯的活動設定檔紀錄。
Note that you don't have to compile your kernel the “Debian way”; but we find that using the packaging system to manage your kernel is actually safer and easier. In fact, you can get your kernel sources right from Linus instead of linux-source-2.6, yet still use the kernel-package compilation method.
注意您可以找到完整的文件,透過使用 kernel-package 它在 /usr/share/doc/kernel-package裡。本節只包含一個簡單的入門指南。
Hereafter, we'll assume you have free rein over your machine and will extract your kernel source to somewhere in your home directory[27]. We'll also assume that your kernel version is 2.6.29. Make sure you are in the directory to where you want to unpack the kernel sources, extract them using tar xjf /usr/src/linux-source-2.6.29.tar.bz2 and change to the directory linux-source-2.6.29 that will have been created.
現在,您可以開始設定您的核心了。如果您已經安裝並正在執行 X11, 請執行 make xconfig﹔否則請執行 make menuconfig (必須已經安裝好 libncurses5-dev)。請花點時間閱讀線上說明並仔細地選擇。如果有任何疑慮,通常把您所不確定的設備驅動程式 (用來管理周邊硬體的軟體,例如以太網路卡、SCSI 控制器等) 一起編譯會比較好一點。注意:對於與特殊硬體無關的其它選項,如果您不瞭解它們,最好保持預設值。不要忘記選擇 “Kernel module loader” 中的 “Loadable module support” (它們預設並沒有被選擇)。否則,您的 Debian 安裝將會遇到問題。
清除原始碼樹並復原 kernel-package 參數。也就是使用 make-kpkg clean。
Now, compile the kernel: fakeroot make-kpkg --initrd --revision=custom.1.0 kernel_image. The version number of “1.0” can be changed at will; this is just a version number that you will use to track your kernel builds. Likewise, you can put any word you like in place of “custom” (e.g., a host name). Kernel compilation may take quite a while, depending on the power of your machine.
Once the compilation is complete, you can install your custom kernel like any package. As root, do dpkg -i ../linux-image-2.6.29-. The subarchitecture_custom.1.0_i386.debsubarchitecture part is an optional sub-architecture, such as “686”, depending on what kernel options you set. dpkg -i will install the kernel, along with some other nice supporting files. For instance, the System.map will be properly installed (helpful for debugging kernel problems), and /boot/config-2.6.29 will be installed, containing your current configuration set. Your new kernel package is also clever enough to automatically update your boot loader to use the new kernel. If you have created a modules package, you'll need to install that package as well.
下面到了重新啟動系統的時刻了﹔請仔細閱讀前述步驟所產生的所有警告資訊,然後執行 shutdown -r now。
For more information on Debian kernels and kernel compilation, see the Debian Linux Kernel Handbook. For more information on kernel-package, read the fine documentation in /usr/share/doc/kernel-package.
[27] There are other locations where you can extract kernel sources and build your custom kernel, but this is easiest as it does not require special permissions.