CSUF LogoCSUF Site Navigation
optics.csufresno.edu

F14 Hosting a Yum Repository Using mock

Department of Electrical and Computer Engineering
Associate Professor Gregory R. Kriehn
Forums
Wiki
F14 Using mock

Mock takes a source RPM (SRPM) and builds the RPM in a sandbox by creating a minimal install of your target OS. It then enters into the chroot to rebuild the SRPM for you. The advantage of using mock when building RPMS is that it ensures that the BuildRequires lines are correct, that there are no missing dependencies, and that it builds cleanly. It also allows for the RPM to be build for different architectures (i686 vs x86_64) and different versions of Fedora. I find it to be extremely useful when building RPMS for the Kriehn Repository.

Installation

If mock is not installed on your system, use yum:
~> sudo yum install mock
Press 'y' to install mock and any dependencies.

Default Configuration

When using mock, you can use the "-r" option to select a particular test configuration. Alternatively, if there is one configuration that you wish to use by default, create a new softlink in /etc/mock to default.cfg:
~> cd /etc/mock
~> sudo ln -s --force [CONFIGURATION.cfg] default.cfg
In this case, [CONFIGURATIN.cfg] is /etc/mock/fedora-15-x86_64.cfg. Next open the default.cfg file and add any repositories you wish to use before the [local] section. The file uses the same format as the .repo files in /etc/yum.repos.d/.

Then open /etc/group and add yourself to the mock group:

mock?x:481:[username]
where [username] is your user name. Save and exit.

Mock Preparation


Create your sourceball using rpmbuild -bs
~> rpmbuild -bs [CONFIG FILE].spec 
where [CONFIG FILE] is the name of your RPM .spec file. Then use Mock to build the RPM:
~> sudo mock -r default.cfg --rebuild [package].src.rpm
When using the default.cfg file, the "-r default.cfg" option is unnecessary. Subtitute a different configuration file if you are building the RPM for a different architecture or version.

Using Mock with Dependencies


If your SRPM has a set of dependencies, first initialize your sandbox with a default, bare bones install:
~> sudo mock --init
Then use mock to try and build the RPM:
~> sudo mock --rebuild ~/linux/rpm/SPRMS/[package].src.rpm
If the build fails, examine the build.log for clues to the missing dependency in /var/lib/mock/[VERSION]/result/build.log, where [VERSION] is the version of the package that you are building. Once you determine your misssing dependency, install it:
~> sudo mock install [DEPENDENCY]
Then rebuild the RPM without cleaning chroot (which would create a new install), since the SRPM does not contain the new dependency information yet.
~> sudo mock --rebuild --no-clean ~/linux/rpm/SPRMS/[package].src.rpm
Repeat the process, as necessary.

Once the RPM successfully builds, edit the RPM's .spec file and add each of the necessary dependencies. Create a new SRPM, re-initialize Mock, and rebuild the RPM from a clean chroot to ensure all the dependencies have been accounted for.

Once your RPM builds, the new packages can be found in /var/lib/mock/[VERSION]/result.

References

http://fedoraproject.org/wiki/Projects/Mock
http://fedoraproject.org/wiki/How_to_create_an_RPM_package
http://fedoraproject.org/wiki/Extras/MockTricks