There will be a short series of posts about RPM. My main goal is to optimizing my systems and my first step is re-compilation. For easing difficulties, I decided to rebuild official RPMs from SRPMs (Source RPMs) with modified SPEC or bumped source tarball to newer version by me.
Okay, step by step, in this post, I will show you how to rebuild RPM without any changes. The package I use to demonstrate is gcalctool-5.24.3-1.fc10, go download the SRPM.
When building a package is advised to not to use root account, therefore we will have the help from mock, which easily put the building process in chroot environment.
Contents
1 Installing mock
yum install mock
2 Preparing a build directory and rebuilding
I choose /home/username/var/rpm/mock, it’s free to choose. Create the directory, then run
mock -r fedora-10-x86_64 \
--resultdir=/home/username/var/rpm/mock/"%(dist)s"/"%(target_arch)s"/ \
--no-clean --no-cleanup-after \
--rebuild gcalctool-5.24.3-1.fc10.src.rpm
First option tells mock what is chroot configuration, which points to a configuration file /etc/mock/fedora-10-x86_64, you can see this option as building target. For example, you can change it to fedora-10-i386 on x86_64 to build a 32-bit package.
Second option tells mock where to store built RPMs. It also categorized by distribution version and target architecture.
Third and fourth options tell mock don’t clean files up before and after. The files are toolchains, dependent packages, etc.
Fifth and last options tell mock that we want to rebuild gcalctool package.
The following is a sample of output:
INFO: mock.py version 0.9.13 starting...
State Changed: init plugins
State Changed: start
INFO: Start(gcalctool-5.24.3-1.fc10.src.rpm) Config(fedora-10-x86_64)
State Changed: lock buildroot
State Changed: clean
State Changed: init
State Changed: lock buildroot
INFO: enabled root cache
State Changed: unpacking root cache
INFO: enabled yum cache
State Changed: cleaning yum metadata
INFO: enabled ccache
State Changed: running yum
State Changed: setup
State Changed: build
INFO: Done(gcalctool-5.24.3-1.fc10.src.rpm) Config(fedora-10-x86_64) 3 minutes 23 seconds
INFO: Results and/or logs in: /home/livibetter/var/rpm/mock/fc10/x86_64/
3 Why is it so slow?
No, it’s not like that. When you create a chroot for building package, it’s not only just put the package’s source in, not that simple. You also need to have system file/directory, toolchain, dependent packages. Most of time is to install dependent packages.
Be sure to ask mock to --no-clean --no-clenup-after.
4 Why does mock still ask me for root password?
Because it is still need to use yum to install dependent packages. Once it finishes, mock will bring up rpmbuild as your account.
5 Installing the built RPM
yum --nogpgcheck localinstall
Since this package is built by our own, it is not signed, therefore we need that option to by pass.
Mock is a lot nicer than using rpm-build and installing on the dependencies on your system. That wouldn't be ideal especially if you only have one production system. The only thing I haven't seen is an option just to extract the SRPM in the chroot so that I can modify the spec file before rebuilding the package. Is there a better way than adding '--no-clean --no-cleanup-after' and building twice?
ReplyDelete@Jason: I do not understand your question, sorry!
ReplyDeleteWith mock it just seems that you give the SRPM and it rebuilds it. Sometimes the RPMs have extra build options that I want to turn on. Before I would just install the RPM and install the dependencies. Then inside /usr/src/redhat/SPECS would contain the spec file which I could modify and then use rpmbuild to rebuild it. Mock seems to just rebuild it without giving you a chance to edit the spec file.
ReplyDeleteIt seems like there should be a better way than to add those two options and rebuild the RPM again.
@Jason I know mock allows we enter the chroot environment, may be we can build SRPM manually in it. Right now, I just use rpmbuild to build SRPM with my modification, then build RPM with mock.
ReplyDelete