Recently I’ve been trying to configure Postfix to support virtual domains and pull the information from MySQL. I’m using CentOS and the default build doesn’t include MySQL support. Even though there is already a build with MySQL support in the Extra’s repository there appears to be a newer version in Updates with a security fix. Since rebuilding SRPMs has always been a breeze in the past I decided just to get the latest SRPM for Postfix and rebuild the package myself.
As I was typing the following command, I noticed a bunch of errors that I’ve never seen while the SRPM was installing. I thought I did something wrong at first and I even opened up the SRPM in midnight commander to take a look at what it was doing.
yum install rpm-build wget 'http://mirror.centos.org/centos/5.2/updates/SRPMS/postfix-2.3.3-2.1.el5_2.src.rpm' rpm -ihv postfix-2.3.3-2.1.el5_2.src.rpm
warning: group mockbuild does not exist - using root warning: group mockbuild does not exist - using root warning: group mockbuild does not exist - using root warning: group mockbuild does not exist - using root warning: group mockbuild does not exist - using root warning: group mockbuild does not exist - using root warning: group mockbuild does not exist - using root warning: group mockbuild does not exist - using root warning: group mockbuild does not exist - using root warning: group mockbuild does not exist - using root ########################################### [100%] warning: group mockbuild does not exist - using root warning: group mockbuild does not exist - using root warning: group mockbuild does not exist - using root
I decided to look up the error and I found a page for http://fedoraproject.org/wiki/Projects/Mock.
Mock creates chroots and builds packages in them. Its only task is to reliably populate a chroot and attempt to build a package in that chroot.
After stumbling across that I was amazed that I hadn’t ran across it before that. This is very nice for production machines which you don’t want to polute by installing development tools and dependencies on the system. Not to mention mock configures all of the build dependencies for a package automatically. Lets get started by running these commands with a user that has access to mock. I’m already going to assume that you have configured mock for the correct system and architecture.
mock clean mock init
This will create a chroot (defaults to /var/lib/mock/<system type>/root) and create the system/architecture with the minimum set of packages to build RPMs. You might be thinking that those steps are unecesarry since the man page says that you can rebuild a SRPM by running “mock <path-to-SRPM>” and that is correct. I’m planning on making changes to the SPEC file before rebuilding and I haven’t found any other options in mock that allow me to do that. Next we will install the build dependencies for Postfix. The no clean option is important.
mock --no-clean installdeps postfix-2.3.3-2.1.el5_2.src.rpm
At this point we have a folder with all of the dependencies to build the RPM. Since we are going to edit the SPEC file we need to install “vi” and the “mysql-devel” packages. You will need to run this as root on your system.
mock-helper yum --installroot /var/lib/mock/<system type>/root install mysql-devel vim-minimal
Now we are ready to enter the chroot and rebuild the package. Switch back to the user that has access to mock and then run.
mock shell
At this point you are now running as root inside the chroot on the system. We want to switch users to the owner of /builddir in order to actually build the RPM. This should be the same user that has access to mock on your actual system. You may edit the RPM macros now if you care about that sort of thing or to configure any additional options.
cd /builddir/build/SPECS vi postfix.spec # change MYSQL 0 to a 1 rpmbuild -bb postfix.spec
At this point the Postfix package should be compiling. When it is finished there should be new RPMs in the directory /builddir/build/RPMS/. Now that they are finished building you can log back in as root on your machine and install the packages. You also might want to clean the mock directory if you care about disk space.

0 Responses
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.