Joomla!

 
  • Increase font size
  • Default font size
  • Decrease font size

Compile Your Own Ubuntu Kernel

E-mail Print PDF

Compile Your Own Ubuntu Kernel

The purpose of this tutorial is to show you how to set up a kernel that is highly tuned for your CPU, in this case a dual core Xeon for a workstation.

Caution: If you do something wrong..it happens...be sure to reboot and select an alternative kernel. You should always have several kernels in case of trouble.

Download and install the necessary tools.

# apt-get install kernel-package libncurses5-dev fakeroot wget bzip2

You must have the source available to create a new kernel.

# apt-get install linux-source

You must be in the /usr/src directory to work.

# cd /usr/src

 

Ubuntu 8.04 Training CD

Build a Linux Kernel Course

Building Kernels Short Course $29.95

This course is designed to help you understand the various kinds of kernels in Linux and help you go through a step by step process to build a custom kernel. This is a basic course on kernel building. There are 7 projects which are available to gain experience in building kernels. To get the most out of this course you should have a Linux machine that you can build kernels on (a test machine).


This directory will contain the necessary headers to build the kernel. These are the source files.

ls
linux-headers-2.6.22-14 linux-source-2.6.22.tar.bz2
linux-headers-2.6.22-14-generic


You need to unpack the source that was downloaded.

# tar xjvf linux-source-2.6.22.tar.bz2

Now you should have a directory that looks like this:

linux-source-2.6.22

Create a symbolic link to this source directory and name it linux.

# ln -s linux-source-2.6.22 linux

Move into the directory, you can use the term linux as it is now a link to that folder.

# cd linux

The config file is a hidden file that has the configuration from the kernel that is installed. You will need to copy that because it has already determined your hardware devices.

# cp /boot/config-2.6.22-14-generic ./.config

Now the fun begins....
You are ready to start menuconfig which will allow you to choose your kernel specifics.

make menuconfig

This opens the menu to start configuration. Select load an Alternative Configuration, which will load the .config file you copied over.

kernel

Here you see it detected the .config file.

kernel

Now work your way through the menus, focusing on the CPU adjustments you need to make. Here the multiple processor option is unchecked because it is only a single processor that is being used.

kernel

Select High Memory Support is your workstation will use more than 4 GB of RAM.

kernel

The kernel is being built for a newer Xeon processor. These specifics for your CPU should help performance and should optimize the reason your purchased the CPU.

kernel

Get rid of some things you will not need, for example, Amateur Radio support. The smaller you make your kernel the faster it will run and the less memory it will use.

kernel

Get rid of PCMCIA support if you are using a Desktop workstation.

kernel

Here I decided to add SELinux support for security.

kernel

Once you have all of your modifications complete save the new .config file.

kernel

Run this command to clean up.

# make-kpkg clean

The next thing you want to do is create a kernel extension so that as you make kernels you are able to tell the versions apart. What I usually do is place my initials and a number so that I can keep track.

# fakeroot make-kpkg - -initrd - -append-to-version=mw1 kernel_image kernel_headers

This will take awhile. It took and hour with a Xeon and 1 GB of RAM.

Now you can install and create .deb files so you can take your kernel to another machine with similar hardware.

# dpkg -i linux-image-2.6.22.9mw1_2.6.22.9mw1-10.00.Custom_i386.deb

# dpkg -i linux-headers-2.6.22.9mw1_2.6.22.9mw1-10.00.Custom_i386.deb

You should now be able to select and test the new kernel when you reboot.

Now when I look in /boot/grub/menu.lst I see listed my new kernel:

title Ubuntu 7.10, kernel 2.6.22.9mw1
root (hd0,0)
kernel /vmlinuz-2.6.22.9mw1 root=UUID=a89c3e7b-3b67-4543-8746-6687acea31f1 ro quiet splash
initrd /initrd.img-2.6.22.9mw1
quiet

title Ubuntu 7.10, kernel 2.6.22.9mw1 (recovery mode)
root (hd0,0)
kernel /vmlinuz-2.6.22.9mw1 root=UUID=a89c3e7b-3b67-4543-8746-6687acea31f1 ro single
initrd /initrd.img-2.6.22.9mw1

Caution: You will need space in the /boot directory to save kernels as you build them. I typically build my /boot directory with 500 MBs of space.

Tip:

Edit your timeout in the /boot/grub/menu.lst and increase it when you are building and trying kernels. That way it will not fly by so fast.

## timeout sec
# Set a timeout, in SEC seconds, before automatically booting the default entry
# (normally the first entry defined).
timeout 8

Tip:

Comment out the hiddenmenu so that you will see the menu on boot.

## hiddenmenu
# Hides the menu by default (press ESC to see the menu)
#hiddenmenu

 

 

 

 

 

 

 

 
BeginLinux.com is designed to provide you with Linux Desktop Training, Applications Training and Server Training. Also included are Linux Distribution CDs, manuals and books.

Polls

What type of video training would you like to see?
 

Linux Distro Choices