Sunday 28 April 2013

How to compile a Kernel and upgrade the kernel version for PC


                                                        How to compile a Kernel
                                                                   

 Downloading and configuring

Step1: Downloading :

      Download a kernel, unpack it into any path and create the “linux” link so that the commands are a little more generic. File name would be linux-x.y.z.tar.bz2, where x.y.z is actual version number.


For example I am taking a file inux-2.6.37.6.tar.bz2 which represents 2.6.37.6 kernel version. Use wget command to download kernel source code. It is common to let the ”linux” link point to the kernel you are currently working with.



 Step2:
   
 Now, get a kernel config file by following these steps.

Step3: configuring
It's a good idea to use the configuration of our current working kernel as a basis for the kernel. Therefore we copy the existing configuration to /usr/src/linux:  

 Step4:
            :/usr/src/linux#

Which brings up the kernel configuration menu. Go to Load an Alternate Configuration File and choose .config (which contains the configuration of your current working kernel) as the configuration file:





Then we need to browse through the kernel configuration menu and make our choices. When we finished and select Exit, answer the following question (Do you wish to save your new kernel configuration?) with Yes:






Step 5: Build The Kernel
   
To build the kernel, execute these two commands:

After --append-to-version= you can write any string that helps you identify the kernel, but it must begin with a minus (-) and must not contain whitespace.
Now be patient, the kernel compilation can take some hours, depending on our kernel configuration and our processor speed.

Step 6: Install The New Kernel
After the successful kernel build, we can find two .deb packages in the /usr/src directory.
They were called linux-image-2.6.37.6-custom_2.6.37.6-custom-10.00.Custom_i386.deb (which contains the actual kernel) and linux-headers-2.6.37.6-custom_2.6.37.6-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:


 


 
(We 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. We can check /boot/grub/menu.lst now, we should find two stanzas for our new kernel there:

Text Box: vi /boot/grub/menu.lst



Now we can see these two stanzas;

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

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

Step 7: update-grub
Step 8: Reboot
Text Box: $  reboot



Step 9:
If everything goes well, it should come up with the kernel. We can check this by running
Text Box: uname -r



This will display something like 2.6.37.6-custom



TO UNISTSLL THE OLDER KERNEL:
This will show you how to find out your current running kernel and how to remove older ones that are not being used by your system. This will help you free up some space and may also improve your system’s performance.
Objectives:
·      Find out your current running kernel
·      Remove older kernels 

Step 1: To get started, press Ctrl – Alt – T to open Terminal. When it opens, run the commands below to view your current running kernel.
uname -r

Next, take notes of your current kernel. DO NOT REMOVE THIS!

Step 2: Next, type the command below to view / list all installed kernels on your system.
dpkg --list | grep linux-image

Next, find all the kernels that which number are lower than your current kernel.  When you know which kernel to remove, continue below to remove it.
Step 3: Finally, run the commands below to remove the kernel you selected.
sudo apt-get purge linux-image-x.x.x.x-generic


When you’re done, run the commands below to update grub2
Step 4:
sudo update-grub2


No comments:

Post a Comment