Friday, May 18, 2012

Compile Debian Kernel (Squeeze) 3.0 and Above with Aufs and squashfs

This tutorial is intended for all who are facing problem with patching the aufs modules using the old methods (2.6.x)

Prerequisites :

Debian (belief that same process holds for Ubuntu)
And again ABC of Linux

Step1:

Open up a terminal

make a directory "linux":

mkdir /root/linux
Step2:

Install all the packages required to build to kernel

aptitude update && aptitude install dkms kernel-package libncurses5-dev wget bzip2 fake-root build-essential 
Step3:

Download the latest sources from kernel.org (3.3.6 were the latest while this post was written) by typing the following in terminal

wget http://www.kernel.org/pub/linux/kernel/v3.0/linux-3.3.6.tar.bz2
Step 4:

Extract the sources to the folder we made earlier

tar xvf linux-3.3.6.tar.bz2 /root/linux
Step5 :

Download the aufs modules and create a patch

mkdir /tmp/aufs
cd /tmp/aufs
git clone git://aufs.git.sourceforge.net/gitroot/aufs/aufs3-standalone.git aufs3-standalone.git
cd aufs3-standalone.git
git checkout origin/aufs3.3
mkdir ../a ../b
cp -r Documentation ../b
cp -r fs ../b
cp -r include ../b
rm ../b/include/linux/Kbuild
cd ..
diff -rupN a/ b/ > /root/linux/aufs.patch
cat aufs3-standalone.git/*.patch >> /root/linux/aufs.patch 

Step 6:

Apply the patch


cd /root/linux
patch -p1 < aufs.patch

 Step 7:

Now start the build process

make clean and make mrproper
Step 8 i: ( if you want to have the same config of your existing kernel)

Configuring the kernel :

If you wish to have the same config of your previous existing kernel follow the steps

cp /boot/config-`uname -r` ./.config
this will load the existing kernel config file

now type

make menuconfig
Step 8 ii : ( if you want to have a custom config of your own)

Configuring the kernel :

copy your custom made .config to the current directory

and type
make menuconfig

Step 9:

You will now be displayed with a screen

Go to Load an Alternate Configuration File and choose .config (this is the .config file we copied to our directory in step 8) and press OK.

Step 10:


Now we will make our own custom kernel


make-kpkg clean fakeroot make-kpkg --initrd --stem extraversion  --revision revision  --append-to-version=-customversion kernel_image kernel_headers


You need to give these 3 values of your own in the above command:
 "extraversion - give your own extraversion for kernel
 revision- the revision you want the kernel to be
customversion   - the custom revision of the kernel "

And sit back for a couple of hours since it takes time

After successful compilation of the kernel you will see two .deb packages in the ../ folder
1. Kernel image file .deb
2. Kernel Header file .deb


Step 11:


Install them by typing the following commands

dpkg -i linux-image-*
dpkg -i linux-headers-*
 (you may type the whole file name as dpkg -i linux-image-3.3.6-custom_3.3.6-custom-1.00.custom_i386.deb depending on whatever is generated in your case) .

Restart your system and you should see your kernel in the grub menu or else verify the kernel version with

uname -a

Congrats you have successfully compiled the Linux kernel for Debian and its derivatives :))

Note:If you face any issues comment this post and i will reply you. 

No comments:

Post a Comment