雖然RedHat有提供kernel的source package(kernel-devel-xxxxx),且只要安裝該套件後kernel source tree即會被放置在 /usr/src/kernels/ 目錄下,但是若我們試著在該kernel source tree裡面進行complie的動作則會出現以下的錯誤訊息:『make[1]: *** No rule to make target `init/main.o', needed by `init/built-in.o'. Stop.』。會造成這種情況的原因並不清楚,總之我們就是不能直接拿kernel-devel套件裡面提供的kernel source tree來打造自己的kernel。因此我們必須要改用kernel-xxxxx.src.rpm還原出的kernel source tree來進行patch與compile的動作。
所需要的套件:
- kernel-2.6.9-55.EL.src.rpm (在此以2.6.9-55.EL這個版本為例)
一、從source rpm檔案中還原出kernel source tree
1.rpm -ivh kernel-2.6.9-55.EL.src.rpm
相關的檔案會被放置在 /usr/src/redhat 的子目錄中(SOURCE,SPECS等),但在RPM Database中將不會有這個套件的安裝記錄,此為正常現象。
2.cd /usr/src/redhat/SPECS
rpmbuild -bp kernel-2.6.spec –target=i686
此指令會把所有RedHat提供的patch檔案patch至kernel source tree中,並將kernel source tree放置於 /usr/src/redhat/BUILD/kernel-2.6.9/linux-2.6.9目錄中。
二、Patch Distribution Kernel
1. 將patch檔案複製到kernel source tree的root dir
eg. cp myhappy.patch /usr/src/redhat/BUILD/kernel-2.6.9/linux-2.6.9
2. cd /usr/src/redhat/BUILD/kernel-2.6.9/linux-2.6.9
patch -p1 < myhappy.patch
三、設定Kernel
1. cd /usr/src/redhat/BUILD/kernel-2.6.9/linux-2.6.9
make menuconfig
3. 此時會有選單出現,請將畫面移到最下方選取 "Load An Alternate Configuration File"
4. 開始設定kernel
四、編譯kernel
1. cd /usr/src/redhat/BUILD/kernel-2.6.9/linux-2.6.9
2. vi MakeFile
EXTRAVERSION = -55-custom
修改EXTRAVERSION的值以免和原本的版本搞混,例如改為-55-custom則最後產生出來的kernel iamge為vmlinuz-2.6.9-55-custom。
3. make clean
注意!不能用make mrproper,否則會連.config(kernel設定檔)也一併清除。
4. make bzImage
5. make modules
6. make modules_install
7. make install
8. 最後要記得修改 /boot/grub/grub.conf
註:
若是不想用 make install 來自動安裝kernel image,也可以改用手工安裝。
1. 將kernel source tree中的arch/i386/boot/bzImage改名為vmlinux-2.6.9-55-custom
2. mkinitrd initrd-2.6.9-55-custom.img `2.6.9-55-custom`
3. cp /usr/src/redhat/BUILD/kernel-2.6.9/linux-2.6.9/System.map \ /boot/System.map-2.6.9-55-custom
4. 將kernel與initrd images放置到 /boot目錄,並修改 /boot/grub/grub.conf