Building Packages for CentOS 5 on Ubuntu/Debian
Normally, when you are using Debian or Ubuntu, you really don't need anything like RHEL or SLES.
But sometimes you will be forced to look over your plate and have to find ways how to make things just work on your chosen distribution.
As written before my colleague Felix and I are working on CentOS Deployment via FAI on Ubuntu. And while we succeeded the starting steps we went further. Means, integrating Puppet during the initial FAI run etc.
For this to happen, you need some software which are not available directly from the enterprise distribution RHEL (CentOS is an real OpenSource Fork of this commercial distribution). For this problem some good people from Fedora started the EPEL Project. The backport packages from Fedora (which is officially the upstream of RHEL) and compile them from source on RHEL 4/5/6.
Sadly, they don't claim officially to be fully compatible with CentOS, so what does a good admin do? Yes, he takes the sources and compiles them for the used distro, in our case CentOS.
But, we didn't want to do that on CentOS itself, we needed a way to do it on Ubuntu.
So, what possibilities do we have?
There are other possibilities but those two are the easiest ones.
First I tried "mach" on lucid, but this wasn't so successful. It didn't work and reading many sources on the internetworks, "mach" is somehow outdated and "mock" is the way to go.
"mock" is in the debian and ubuntu repositories, so it's just an "apt-get install mock" away from work.
But, "mock" in Debian and Ubuntu (unmodified sync from debian) doesn't have any support for CentOS.
Therefore, we needed to find some bits and pieces to get "mock" to work.
Here we go...this is the configuration for starting a "CentOS build system on Debian/Ubuntu".
config_opts['root'] = 'centos-5-x86_64'
config_opts['target_arch'] = 'x86_64'
config_opts['chroot_setup_cmd'] = 'install buildsys-build'
config_opts['dist'] = 'centos5' # only useful for --resultdir variable subst
config_opts['yum.conf'] = """
# grub/syslinux on x86_64 need glibc-devel.i386 which pulls in glibc.i386, need to exclude all
# .i?86 packages except these.
# exclude=[1-9A-Za-fh-z].i?86 g[0-9A-Za-km-z].i?86 gl[0-9A-Za-hj-z].i?86 gli[0-9A-Zac-z].i?86 glib[0-9A-Za-bd-z].i?86
exclude=[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefhijklmnopqrstuvwxyz].i?86 g[abcdefghijkmnopqrstuvwxyz].i?86 glib2.i?86 glib-.i?86 glib.i?86 -devel.i?86 ruby-libs*.i?86
baseurl=http://<hostname of your nearest centos mirror>/centos/5/os/x86_64/
baseurl=http://<hostname of your nearest centos mirror>/centos/5/updates/x86_64/
You save the file in /etc/mock and name it centos-5-x86_64.cfg.
After creating this file you need to edit the file "/etc/mock/site-defaults.cfg".
Find the line with the comment "# config_opts['plugin_conf']['ccache_enable'] = False"
Remove the "#" and change the value from "False" to "True".
Now you are able to rebuild source rpms from EPEL.
To do that just download from src.rpm from the EPEL repository and save it somewhere.
Now execute the following:
$ sudo mock -r "centos-5-x86_64" --arch="x86_64" <filename of src.rpm>
"mock" will now create something like a chroot and a package cache and a chroot tarball (you know that from sbuild or pbuilder) and will build your src.rpm inside a clean chroot.
No need to pollute your system with cruft. It needs some time for the first run, but after that it's quite speedy, just like pbuilder.
The resulting binary you will find in "/var/lib/mock/centos-5-x86_64/result/"
Be careful, it will clean that directory when you run another build, so catch the result before you do another build run.
Now, it could be that you build a package which is a build dependency of another package. To use this newly build package, you should think about creating your own yum repository.
This is also easily doable on Ubuntu or Debian. You just need an webserver and the "createrepo" tool.
"createrepo" is in the package "createrepo" (surprise, surprise), so "apt-get install createrepo" is your friend to success.
You create a directory e.g. "/srv/repositories/centos/5/mypkgs/x86_64/RPMS" and move the resulting binary packages for your x86_64 arch into this directory.
Now you just execute:
$ createrepo /srv/repositories/centos/5/mypkgs/x86_64/
and you are done with creating a yum repository.
You can now add this repository to the centos-5-x86_64.cfg file, and with the next call to mock all package caches will be updated and your src.rpm, which depends eventually on a package you just put in your own package repository, will build successfully with your packages inside your yum repository.