Pages

Thursday, May 20, 2010

How to compile Linux kernel on Ubuntu?

Following are the steps to compile a kernel source code on ubuntu-

Steps:

  1. Change to root : su

  1. Update the package manager : apt-get update

  1. Get new make utility : apt-get install build-essential

  1. Optional - To create dep : apt-get install kernel-package libncurses5-dev fakeroot wget bzip2

  1. Download linux source : cd /usr/src

Download patches: v2.6/testing/patch-2.6.27-rc1.bz2
2.6.27-rc1-mm.bz2

  1. Then we unpack the kernel sources and create a symlink linux to the kernel sources directory:

tar xvjf linux-2.6.18.1.tar.bz2
ln -s linux-2.6.18.1 linux
cd /usr/src/linux


  1. Apply patches:
bzip2 -dc patch-2.6.27-rc1.bz2 | patch -p1 
bzip2 -dc 2.6.27-rc1-mm.bz2 | patch -p1 

  1. Execute : make clean
make mrproper

  1. Configure kernel:
Copy already existing config file:
cp /boot/config-`uname -r` ./.config

make menuconfig
Go to Load an Alternate config file. Enter .config and enter. Exit


  1. Make kernel: make && make modules_ install && make install

Check if depmod is already not done.
If not done then type: depmod 2.6.27-rc1-mm


  1. To use initrd then get yaird:
apt-get install yaird

  1. Execute:
mkinitrd.yaird –o /boot/initrd.img-2.6.27-rc1-mm1 2.6.27-rc1-mm1

If this doesn’t work then execute:
mkinitramfs –o /boot/initrd.img-2.6.27-rc1-mm1 2.6.27-rc1-mm1

Update grub (/boot/grub/menu.lst): update-grub
Check the menu.lst file and see the entry of new kernel

  1. Reboot