How to Build Custom Xen Kernel Based on CentOS/RHEL Xen Kernel

The HOWTO on compiling CentOS kernel based on RHEL code base (currently 2.6.18) is overly complicated. Follow the following steps to build a custom Xen kernel, maybe with different kernel configuration.

  • Setup the rpmbuild directory, and install prerequisite packages.
    mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
    sudo yum -y install rpm-build redhat-rpm-config unifdef kernel-devel kernel-xen-devel
  • Grab the kernel source RPM, you want to modify and compile, and install it.
    wget -c`uname -r`.src.rpm
    rpm -i kernel-`uname -r`.src.rpm
  • Create the spec file for the downloaded kernel
     cd ~/rpmbuild/SPECS
     rpmbuild -bp --target=`uname -m` kernel-2.6.spec
  • Modify the config to your needs. The config file are stored in ~/rpmbuild/SOURCES.
  • Modify the buildid. This is a good practice, if you are making extensive changes.
     cd ~/rpmbuild/SPECS
     sed -ibak -e 's/#% define buildid/%define buildid .ppadala/' kernel-2.6.spec
  • Build the kernel
     cd ~/rpmbuild/SPECS
     sudo rpmbuild -bb --with xenonly --without debug --without debuginfo --target=`uname -m` kernel-2.6.spec
  • This will generate a RPM that you can install on other machines as well.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>