« psacct & checkinstall 使用備忘 | 首頁 | 遠端安裝 Fedora Core Linux »

2006年11月22日

How To Compile A Kernel

環境: Fedora Core 6 Linux @ x86 Platform

傳統編譯方式

#切換為 root 身份
su -

cd /usr/src

#下載 Kernel Source
wget
ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.18.tar.bz2

#下載 patches (本例為下載 prepatches)
wget
http://www.kernel.org/pub/linux/kernel/v2.6/testing/patch-2.6.19-rc6.bz2

tar jxf linux-2.6.18.tar.bz2

ln -s linux-2.6.18 linux

cd linux

#上 patches (bzip2 -dc 可用 bzcat 代替)
bzip2 -dc ../patch-2.6.19-rc6.bz2 | patch -p 1

#複製現行 kernel config, 作為新 kernel 的預設值
cp /boot/config-$(uname -r) ./.config

make menuconfig

make

make modules_install

make install

#將新 kernel 的 config file 複製到 /boot
cp .config /boot/config-2.6.19-rc6

kernel v2.4 的 make 方法:

make menuconfig
make dep

make bzImage
make modules
make modules_install
make install

以 Fedora 的方式編譯核心

#切換為 root 身份
su -

yum install rpm-build rpmdevtools unifdef

cd ~

#在家目錄建立 rpmbuild 相關路徑
fedora-buildrpmtree

#下載 fedora 的 kernel source rpm
wget
http://download.fedora.redhat.com/pub/fedora/linux/core/6/source/SRPMS/kernel-2.6.18-1.2798.fc6.src.rpm

rpm -ivh kernel-2.6.18-1.2798.fc6.src.rpm (忽略 warning: user brewbuilder does not exist 訊息)

cd ~/rpmbuild/SOURCES/

#下載 patches (原 rpm 封裝已提供 patch-2.6.18.1)
wget
http://www.kernel.org/pub/linux/kernel/v2.6/patch-2.6.18.3.bz2

cd ~/rpmbuild/SPECS/

#修改使用的 patches
vi kernel-2.6.spec

Patch1: patch-2.6.18.1.bz2patch-2.6.18.3.bz2

重覆方框裡的步驟, 直到 rpmbuild 成功

rpmbuild -bp --target=x86_64 kernel-2.6.spec
(--target 參數可為 i386, i586, i686, 或是 x86_64; 預設為 i386)

(若出現以下訊息, 就得修改 kernel-2.6.spec 裡的 patch 設定)

Patch #300 (linux-2.6-ppc-dac960-ipr-clash.patch):
+ patch -p1 -s
Reversed (or previously applied) patch detected! Assume -R? [n] (按 Enter 鍵帶過)
Apply anyway? [n] (按 Enter 鍵帶過)
...

(記住 300 這個數字)

vi kernel-2.6.spec

(將 Patch300 與 %patch300 這兩行最前面加上註解符號, 注意大小寫)

#Patch300:...

#%patch300 -p1

(我的環境裡, 總共註解掉: 300, 308, 1302, 1424, 1434, 1700, 1730, 2400, 2800, 2801)

cd ~/rpmbuild/BUILD/kernel-2.6.18/linux-2.6.18.i386

#設定延伸版號, 可任意設定 (如設定為 .3 則編譯後的版號為 2.6.18.3)
vi Makefile

EXTRAVERSION = .3

make menuconfig

make rpm

cd ~/rpmbuild/RPMS/i386/

#安裝編譯完成的新 kernel, 亦可複製給其他 Fedora 環境安裝
rpm -ivh kernel-2.6.18.3-1.i386.rpm

#第二個參數為新 kernel 的版號
mkinitrd /boot/initrd-2.6.18.3.img 2.6.18.3

vi /boot/grub/menu.lst

title Fedora Core (2.6.18.3)
root (hd0,0)
kernel /vmlinuz-2.6.18.3 ro root=LABEL=/1 rhgb quiet
initrd /initrd-2.6.18.3.img


References:

Related Links:

Posted by Jamyy at 2006年11月22日 11:05

Trackback Pings

TrackBack URL for this entry:
http://cha.homeip.net/cgi-bin/mt/mt-tb.cgi/241