From Fedora Project Wiki

Revision as of 15:12, 28 February 2010 by Hreese (talk | contribs) (cvs.fedora.redhat.com -> cvs.fedoraproject.org)

Building an upstream kernel.

Sometimes a Fedora developer may ask you to try building and installing an upstream kernel (possibly with a patch added) for testing. If there are multiple iterations, it may be quicker for you to do this than for the developer to turn around several RPMs.

Installing the necessary tools

First, as root, install the tools we'll need.

yum install git gcc ccache

Then as a non-root user, perform these steps..

Getting the sources

git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git

This will clone the entire upstream tree. This may take a while depending on your connection speed.

cd linux-2.6

Applying patches

If you were asked to apply any patches by the developer, this is the stage at which we would do so. These would typically be applied using a command something like..

cat ~/testpatch.diff  | patch -p1

If you have to try multiple different patches individually, you can unapply the previous one after testing by adding -R on the end of the above command.

Configuring the kernel

Chances are that the kernel you are running is older than the one you are about to configure. This means there will be new options. There are several possibilities here.

  • If the developer has pointed you at a specific config file to use, save it in the linux-2.6 directory with the filename .config
  • You can take your existing .config file by using the command cp /boot/config-uname -r .config

When you run the next step, you'll be asked (potentially lots of) questions about all the new options. Just hitting return 'should' always pick the safe decision for each option. However, it's worth taking care and reading each option, as this isn't always the case, and they may introduce new features your distro isn't capable of running, which may result in a non-booting system.

  • Get a .config from rawhide. This is a little convoluted, but is the best method to get a 'fedora' .config for the kernel. Because rawhide tracks upstream very closely, chances are it'll have an up to date .config file. To check out and generate the config, do this.
 cvs -d:pserver:anonymous@cvs.fedoraproject.org:/cvs/pkgs co kernel
cd kernel/devel ; make prep

The generated config files are now in kernel-2.6.24/linux-2.6.24.noarch/configs/ (Note the version number may change). Pick the right one for your architecture.

With the config in place, you are now ready to move on to the next step.

Building the kernel

$EDITOR Makefile

Change the EXTRAVERSION line to add something on the end. For example, if it reads "EXTRAVERSION = -rc5" change it to "EXTRAVERSION = -rc5-dave" (what you choose is only relevant for the final part of this procedure)

make oldconfig
make bzImage
make modules

(become root)

make modules_install
make install

You have now built and installed a kernel. It will show up in the grub menu next time you reboot.

Rebuilding

If you have been asked to try several different things, the procedure once you have already built the tree once is mostly the same. A make clean is recommended between builds. This will leave the .config in place, so you can skip that step above and proceed straight to the make bzImage part of the steps above. Because we installed ccache in the first step, subsequent builds may go a lot faster as the compiler hits files that haven't changed since the last time it built them.

Cleaning up

Once you have tested the kernel, and you've booted back to one of your kernels installed from an RPM, you can clean up the files that the above procedure installed by becoming root, and calling these commands. (Be sure to get the kernel version correct!) Remember above, we changed EXTRAVERSION to add a 'tag' to the kernel ? All the files it installed will have this as part of the filename. So you should be able to use wildcards to delete them safely using commands similar to those below. (Just replace 'dave' with whatever tag you chose)

rm -f /boot/config-2.6.*dave* /boot/initrd-2.6.*dave* /boot/vmlinuz-*dave* /boot/System.map-*dave*
rm -rf /lib/modules/2.6*dave*

Finally, (as root), edit /boot/grub/menu.lst and delete the four lines relating to your kernel (They should be easy to spot, they'll be the ones with your tag). They'll look something like this..

title Fedora Core (2.6.22-rc3-dave)
root (hd0,0)
kernel /vmlinuz-2.6.22-rc3-dave ro root=/dev/md0
initrd /initrd-2.6.22-rc3-dave.img