2008年1月3日 星期四

How To Compile A Kernel - The Ubuntu Way

http://www.howtoforge.com/kernel_compilation_ubuntu

1.Preliminary Note
#su root
#apt-get update

2.Install Required Packages For Kernel Compilation
#apt-get install kernel-package libncurses5-dev fakeroot wget bzip2
3.Download The Kernel Sources
#cd /usr/src
#wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.18.1.tar.bz2
#tar xjf linux-2.6.18.1.tar.bz2
#ln -s linux-2.6.18.1 linux
#cd /usr/src/linux
4.Apply Patches To The Kernel Sources (Optional)
#bzip2 -dc /usr/src/patch.bz2 patch -p1 --dry-run
#bzip2 -dc /usr/src/patch.bz2 patch -p1

5.Configure The Kernel
#cp /boot/config-`uname -r` ./.config
#make menuconfig
6.Build The Kernel
#make-kpkg clean
#fakeroot make-kpkg --initrd --append-to-version=-custom kernel_image kernel_headers

7.Install The New Kernel
#cd /usr/src
#ls -l
On my test system they were called linux-image-2.6.18.1-custom_2.6.18.1-custom-10.00.Custom_i386.deb (which contains the actual kernel) and linux-headers-2.6.18.1-custom_2.6.18.1-custom-10.00.Custom_i386.deb (which contains files needed if you want to compile additional kernel modules later on). I install them like this:
#dpkg -i linux-image-2.6.18.1-custom_2.6.18.1-custom-10.00.Custom_i386.deb
#dpkg -i linux-headers-2.6.18.1-custom_2.6.18.1-custom-10.00.Custom_i386.deb
(You can now even transfer the two .deb files to other Ubuntu systems and install them there exactly the same way, which means you don't have to compile the kernel there again.)

That's it. You can check /boot/grub/menu.lst now, you should find two stanzas for your new kernel there:


#vi /boot/grub/menu.lst
The stanzas that were added on my test system look like these:

title Ubuntu, kernel 2.6.18.1-custom
root (hd0,0)
kernel /boot/vmlinuz-2.6.18.1-custom root=/dev/sda1 ro quiet splash
initrd /boot/initrd.img-2.6.18.1-custom
savedefault
boot

title Ubuntu, kernel 2.6.18.1-custom (recovery mode)
root (hd0,0)
kernel /boot/vmlinuz-2.6.18.1-custom root=/dev/sda1 ro single
initrd /boot/initrd.img-2.6.18.1-custom
boot

沒有留言: