Homepage  |   Computer Class  |   About Me
 
§ Make kernel over Debian §

Chen Chih-Chia <pigfoot@CDPA.nsysu.edu.tw>

June 17, 2002

Abstract

一般來說,通常我都會使用 apt 來升級 kernel。當然,升級 kernel 有兩個主要的理由,第一個就是新硬體或是對新硬體控制的需求,比方說加了一顆新的介面卡,新 kernel 才有支援,或是這邊我要加上的 xfs patch。第二個就是一些重大 bug 的時候。當然,在我這篇 Make kernel over Debian 文章裡,會教大家如何利用 apt 在五分鐘內升級好 kernel,以及手動升級 Debian 式的 kernel。

Make kernel via apt tool

首先,我必須要說明,雖然這種方式很簡單,但是偷懶一定會有報應的 ^^ 也就是說我們無法選擇我們所需要的項目,而且會喪失最佳化。一般而言,Debian developer 在維護 kernel image 時,都會盡可能的將所有的選項都編成 module,讓我們在可需要的時候載入進來。而且最佳化對我來說,並不會增加太多的 performance,所以我通常是使用 apt 來升級 kernel 的。但是如果你要加上一些 patch,或是調一些功能,你就必須參考以下的方法了。

使用的方式很簡單,和一般安裝軟體的時候一樣:

# apt-get update
# apt-get install kernel-image-2.4.20-586tsc

其中要注意的是,2.4.20 是 kernel 版本,後面的是你這機器的處理器。這個例子是使用 pentium 舊系列的 CPU。如果是 K6 或是 K6-2,請使用 kernel-image-2.4.20-k6,K7 請使用 kernel-image-2.4.20-K7,以此類推。

裝好之後,他會問你:

You are attempting to install an initrd kernel image (version 2.4.18-586tsc)
This will not work unless you have configured your boot loader to use
initrd. (An initrd image is a kernel image that expects to use an INITial
Ram Disk to mount a minimal root file system into RAM and use that for
booting).
As a reminder, in order to configure lilo, you need to
add an 'initrd=/initrd.img' to the image=/vmlinuz
stanza of your /etc/lilo.conf
I repeat, You need to configure your boot loader. If you have already done
so, and you wish to get rid of this message, please put
  `do_initrd = Yes'
in /etc/kernel-img.conf. Note that this is optional, but if you do not,
you'll contitnue to see this message whenever you install a kernel
image using initrd.
Do you want to stop now? [Y/n]

意思就是提醒你要使用 initrd,也就是要在 /etc/lilo.conf 要設好 initrd=/initrd.img,如果你不希望每次都提醒你,你可以在 /etc/kernel-img.conf 加上 do_initrd = Yes 即可。

然後仔細檢查 lilo.conf 的設定,之後打 lilo -v -v 來寫入,接著重開機就可以使用新的 kernel 囉!瞧!方式就是如此簡單 ^^

Make kernel via kernel-package

這個 section 會使用 debian 的一些 tool,重新編譯自訂的 kernel,而且我這裡會加上 xfs 的 patch 當作例子。首先,如果你沒有裝 kernel-package,initrd-tools,gcc,libc6-dev,libncurses5-dev 的話,要安裝他們:

# apt-get install kernel-package initrd-tools gcc libc6-dev libncurses5-dev
# rehash

緊接著我們要先安裝 kernel 2.4.20 的 source。

# apt-get update
# apt-get install kernel-source-2.4.20

kernel 2.4.20 的 source 就會被放置到 /usr/src。我們到 /usr/src 並且解開該壓縮檔:

# cd /usr/src
# tar jxvf kernel-source-2.4.20.tar.bz2

解開之後,我們先看看 /usr/src/kernel-source-2.4.20/README.Debian,發現事實上 Debain 加了不少 patch:

除了這些之外,還加上了 52 個修正 patch。我們要使用最多的模組,所以我偷偷利用 kernel-image 設定的 config 選項。我將它放到 http://www.sojia.org/~pigfoot/mirror/kernel-config/ ,請根據你的 CPU 來覆寫 /usr/src/kernel-source-2.4.20/.config。對了,盡量不要修改 /usr/src/kernel-source-2.4.20/arch/i386/defconfig ,雖然這是預設值,但是自行修改後,之後的 patch 步驟將會失敗。所以我複製到使用者設定檔的位置:

# wget http://www.sojia.org/~pigfoot/mirror/kernel-config/config-2.4.20-debian-586tsc
# cp config-2.4.20-debian-586tsc /usr/src/kernel-source-2.4.20/.config

接著就是到 /usr/src/kernel-source-2.4.20 裡執行 make menuconfig。不過要注意,使用 menuconfig 要裝 libncurses5-dev 。當然,我已經之前已經安裝過了。自己有特殊需求請自行修改自己的參數。對了,我在編譯 Character devices 的 Specialix RIO system support 每次都會失敗,所以最好將它取消。這裡是我最後的 config。 make menuconfig 的步驟如下:

# cd /usr/src/kernel-source-2.4.20
# make menuconfig

O.K. 然後我們要加上 xfs 的 kernel patch,步驟如下:

# apt-get install kernel-patch-xfs

預設會裝到 /usr/src/kernel-patches,然後檢查 /etc/kernel-pkg.conf 是否有下面這一行,讓我們 make-kpkg 的時候自動 patch:

# patch_the_kernel :=YES

最後就是最終步驟,make-kpkg:

# make-kpkg --revision sojia+xfs.20030414 --initrd --added-patches xfs kernel_image

記的要在 /usr/src/kernel-source-2.4.20 的目錄下執行。其中 --revision 是版本,--added-patches 是加上 patch,如果有兩個要用逗號分開,如下:

# make-kpkg --revision sojia+xfs.20030414 --initrd --added-patches xfs,evms kernel_image

首先他會出現下列的訊息,提醒你如果用了 --initrd 的話,記的要把 initrd 編進 kernel,我們的確把他編進 kernel 了,所以這裡按 Enter 直接略過即可:


Warning: You are using the initrd option, that may not
work unless you have applied the initrd cramfs patch to
the kernel, or modified mkinitrd not to use cramfs by
default. The  cramfs initrd patch, is included in the
Debian supplied kernel sources, but is not present in
pristine kernel sources.
By default, I assume you know what you are doing, and I
apologize for being so annoying. Should I abort[Ny]?

如果有 patch,就會有以下訊息,要特別注意,因為 patch 失敗會自動取消 patch:

Testing whether SGI XFS Filesystem Support patch for 2.4.20 applies (dry run):
SGI XFS Filesystem Support patch for 2.4.20 succeeded

如果 patch 成功會接著詢問你一些參數:

Quota support (CONFIG_QUOTA) [Y/n/?]
  Old quota format support (CONFIG_QFMT_V1) [N/y/m/?] (NEW) m
  VFS v0 quota format support (CONFIG_QFMT_V2) [N/y/m/?] (NEW) m
  Compatible quota interfaces (CONFIG_QIFACE_COMPAT) [N/y/?] (NEW) n
XFS filesystem support (CONFIG_XFS_FS) [N/y/m/?] (NEW) y
  ACL support (CONFIG_XFS_POSIX_ACL) [N/y/?] (NEW) y
  Realtime support (EXPERIMENTAL) (CONFIG_XFS_RT) [N/y/?] (NEW) n
  Quota support (CONFIG_XFS_QUOTA) [N/y/?] (NEW) y
  DMAPI support (CONFIG_XFS_DMAPI) [N/y/?] (NEW) n
  Debugging support (EXPERIMENTAL) (CONFIG_XFS_DEBUG) [N/y/?] (NEW) n
  Pagebuf debugging support (EXPERIMENTAL) (CONFIG_PAGEBUF_DEBUG) [N/y/?] (NEW) n

然後就一直嘩啦嘩啦。我在 K6-2 350Mhz 的機器大約會編譯 3 個小時半左右。最後就造出了我們的 kernel package 囉!剩下來的安裝和上面的相同,包括檢查 lilo.conf 等等。

# cd /usr/src
# dpkg -i kernel-image-2.4.20_XFS.1_i386.deb

到目前為止就大公告成啦 ^^

Related Link

 

 
  Contact Me  |   Apply NSYSU Dorm-Net  |   NSYSU-CDPA Dorm-Net Web Mail  |   NSYSU-CDPA Dorm-Net Web TV
  ©All rights reserved. Recommend: Mozilla, FireBird, Opera, MSIE6 Browsers.
  Last Updated: Monday, November 3, 2003 4:59 PM