Tuesday, January 20, 2009

Building Fedora 10 kernel

Preaparing the build environment:
In order to create the file system environment we need to run the following command where we want to build the kernel (If missing, install package rpmdevtools):

Now, We are having the rpmbuild directory which contain the following directories : BUILD, RPMS, SOURCES, SPECS and SRPMS.

Note: the rpmdevtools was changed between fedora 9 and 10, in 9 we had to call fedora-buildrpmtree.
Other note: Some of the operations required root permissions, you can run it
as root or use "su", just remember that the rpmbuild directory is expected in the current user home directory and pay attention to the directory permission.

To set the build in a specific path (e.g. ~/rpmbuild) add the following to the ~/.rpmmacros file:
%_topdir %(echo $HOME)/rpmbuild #path to your custom
build dir

Download and install the kernel source:
Now, we should downoad the kernel source from http://kojipkgs.fedoraproject.org/packages/kernel, since my kernel version is I will download the file kernel-

After the download completed, extract the rpm by typing (you can ignore the "warning: group mockbuild does not exist - using root" messages):
#rpm -ivh kernel-

Preparing the build (in my case, for i686):
#cd rpmbuild/SPECS
#rpmbuild -bp --target=i686 kernel.spec

Building the kernel rpm:
Note: For this sample, I will build the kernel without any configuration changes.

Go to the build directory and start the rpm build.
#cd rpmbuild/BUILD/kernel-2.6.27/linux-2.6.27.i686
#make rpm
This is going to take some time .....

Creating the ram disk:
initrd image creation:
Since the mkinitrd function searching the built modules under /lib/modules/, I created a soft link from there to the place we have built the modules
(there must be more elegant way ...)
#cd /lib/modules/
# ln -s <build path>/rpmbuild/BUILDROOT/kernel-
#cd <build path>/rpmbuild/BUILDROOT/kernel-.6.27.9-1.i386/boot
#mkinitrd /boot/initrd-

Installing the new kernel:
Now, We need to copy the generated files from the <build path>rpmbuild/BUILDROOT/kernel-
directory to the /boot directory in the target machine:

In the /etc/grub.conf file we need to add
an entry for the new kernel:
title myBuild (
root (hd0,0)
kernel /boot/ofer/vmlinuz- ro root=UUID=<your uuid> rhgb quiet
initrd /boot/ofer/initrd-

Reboot the machine, choose the new kernel in the grub screen, and that it :-)

1 comment:

prince said...

hi, can u help me, explain to me these points
1.To set the build in a specific path (e.g. ~/rpmbuild) add the following to the ~/.rpmmacros file:
%_topdir %(echo $HOME)/rpmbuild #path to your custom build dir .
what does it mean by path to your custom build dir .
2.root (hd0,0)
kernel /boot/ofer/vmlinuz- ro root=UUID= rhgb quiet
initrd /boot/ofer/initrd-
so should change the number of hd0 or not important because i have just one portion in my laptop.
3. i can't run this commend
#mkinitrd /boot/initrd-
when i run it got kernel not found .
my regards. libya in my heart .