Get me outta here!

Friday, 7 February 2014

CONFIGURING AND INSTALLING CUSTOM KERNEL

In this post I am going to describe how to configure and install your own kernel.

Tools required to configure and compile kernel:

Make sure you have following kernel tools installed on you system.

sudo apt-get install build-essential kernel-package libncurses5-dev

If you are running a 64-bit version you may probabily need to install 32-bit libraries because some distributions 32-bit libraries in 64-bit editions.


sudo apt-get install ia32-libs


Before you can configure your kernel, of course, you need to have source code of your kernel. You can get a copy of kernel from www.kernel.org

So, the first step in configuring your kernel is to download your kernel source code. After you have downloaded the kernel you need to get patches that you wish to attach with your kernel. 

I have downloaded BFS scheduling patch from ck.kolicas.org. Here, select patches link and browse through appropriate version of your kernel and you will get the patch from there. BFS is alternative CPU scheduler. Another patches are from algo.ing.unimo.it. These are BFQ patches. BFQ is a disk I/O scheduler.

Thats it, we are ready with our kernel source code and the patches that we want to apply. 

Now we need to untar the kernel source code. To do so, open the terminal and change directory to the location where kernel source tar file is located. For untarring the source code enter the following command:
tar -Jxvf linux.x.xx.x.tar.xz 

where x stands for your kernel version.
  
You will see lots of files being untarred once you hit enter. Now a new directory is created named linux-<kernel_version>. 

Now you need to symbolically link your kernel source directory. This is because when actual compiling will be done, some of the drivers and modules would look for the directory named “linux”. To link the directory enter following command in your terminal:

ln -s linux-<kernel_version> linux

<kernel_version> refers to your kernel source code version.

 
Now cd yourself into the linux directory by:

cd linux

Now is the turn to apply patches that we downloaded. To apply patch enter following command into your terminal:

patch -p1 < 0001-block-cgroups-kconfig-build-bits-for-BFQ-v6r2-3.11.patch

patch -p1 < 0002-block-cgroups-kconfig-build-bits-for-BFQ-v6r2-3.11.patch

patch -p1 < 0003-block-cgroups-kconfig-build-bits-for-BFQ-v6r2-3.11.patch

patch -p1 < 3.11-sched-bfs-441.patch

patch -p1 < 3.11-sched-bfs-442.patch

Ok so now we have applied all the patches that we wanted to apply to our kernel.

Now its time to configure our kernel.

To configure your kernel enter following command in your terminal window:



make menuconfig



You will see a blue-grey screen with lots of configuration options. 


Here we will select all the patches that we applied and make some other useless options uncheck in order to compress our kernel. 

Following changes are applied :

1. To change the processor type :

Processor type and features > Processor family

Select the type of processor your machine is running on. By default it is Generic, for Intel dual core and higher versions you can select Core 2/newer Xeon.

2. Disable AMD MCE features, as my machine is non-AMD.

3. Disable AMD microcode loading support.

4. Disable Dell laptop support, as my machine is non-Dell.

5. Select Intel Low Power Subsystem Support

6. Select Preemption model and select Low-latency Desktop option. This will provide better desktop resposiveness.

7. To enable BFQ I/O schedular patch

Select Enable the block layer > I/O Schedulers

Enable BFQ I/O Scheduler

Enable BFQ hierarchical scheduling support

8. Set Default I/O scheduler to BFQ

Ok so these are the changes that we made to our kernel. Press <Esc> to come out of the configuration menu and select “Yes” when asked save new configuration.

Now we need to make system ready for compiling process. We do that by running:

make-kpkg clean



Now before starting the compilation I want to specify that we will create a deb package of the compiled kernel so that it could be easily installed on Debian-based OSes.

To start compilation and create deb packages enter following command in your terminal window:

fakeroot make-kpkg –initrd –append-to-version=-kernel-love kernel-image kernel_headers

Depending on your machine, compilation process may vary from 45 min to 1 hour or may be more. Have patient and have a cup of tea. :)
After the compilation process is over you will have two deb files one for kernel-image and another for kernel-headers.

From the terminal you can install these packages by entering following command:

dpkg -i linux-headers-3.11.4-my-kernel-love_3.11.4-my-kernel-love-10.00.Custom_amd64.deb



dpkg -i linux-image-3.11.4-my-kernel-love_3.11.4-my-kernel-love-10.00.Custom_amd64.deb

After installing the deb packages, you will need to modify your grub in order to boot from your kernel. You can do so by using “Grub Custmoizer”. To install Grub Customizer follow following steps:

1. Add following ppa:

sudo add-apt-repository ppa:danielrichter2007/grub-customizer

2. Update your repository:

sudo apt-get update

3. Install Grub Customizer:

sudo apt-get install grub-customizer

Thats all. You are done with your own version of kernel. Open the Grub Customizer and set your kernel as the first boot kernel in the given list.

0 comments: