Wednesday, November 24, 2010

How to Compile a Kernel in Debian

Here you will see how to build Debian deb package for linux kernel source.

Install Tools

First of all install few tools:
apt-get install kernel-package libncurses5-dev fakeroot bzip2 build-essential

Prepare Working Directory

  1. Add users to group src:
    usermod -a -G src user1
    
  2. Ensure group src is the owner of /usr/src:
    chgrp -R src /usr/src
    chmod g+s /usr/src
    chmod -R g+w /usr/src
    

Download Kernel Source

  1. Change your working directory to /usr/src/:
    cd /usr/src
    
  2. Download kernel source from kernel.org:
    wget -c http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.36.tar.bz2
    
  3. Decompress kernel source and create a symbolic link:
    tar xjf linux-2.6.36.tar.bz2
    test -L linux && rm linux 
    ln -s linux-2.6.36 linux
    cd linux
    

Configure Kernel

  1. Let use existing kernel configuration as a start point:
    cp /boot/config-`uname -r` /usr/src/linux/.config
    
  2. Launch kernel configuration tool:
    make menuconfig
    
  3. Start kernel build (this may take from 20 mins to few hours depending on your hardware and number of CPUs):
    time fakeroot make-kpkg -j 2 --initrd --append-to-version=-custom kernel_image kernel_headers
    
  4. Once build finishes you should get two .deb files in parent directory:
    deby01:/usr/src$ ls -l *.deb
    
    linux-headers-2.6.36-custom_2.6.36-custom-10.00.Custom_amd64.deb
    linux-image-2.6.36-custom_2.6.36-custom-10.00.Custom_amd64.deb
    

Install Kernel

  1. Install linux kernel and image deb packages by issuing the following command:
    dpkg -i *.deb
    
  2. Restart your computer:
    shutdown -r now
    
  3. Once it restarts check the kernel version you are using:
    deby01:~$ uname -r
    2.6.36-custom
    
Enjoy your custom kernel.

No comments :

Post a Comment