How to rebuild libguestfs from source on RHEL or CentOS 7

Three people have asked me about this, so here goes. You will need a RHEL or CentOS 7.1 machine (perhaps a VM), and you may need to grab extra packages from this preview repository. The preview repo will go away when we release 7.2, but then again 7.2 should contain all the packages you need.

You’ll need to install rpm-build. You could also install mock (from EPEL), but in fact you don’t need mock to build libguestfs and it may be easier and faster without.

Please don’t build libguestfs as root. It’s not necessary to build (any) packages as root, and can even be dangerous.

Grab the source RPM. The latest at time of writing is libguestfs-1.28.1-1.55.el7.src.rpm. When 7.2 comes out, you’ll be able to get the source RPM using this command:

yumdownloader --source libguestfs

I find it helpful to build RPMs in my home directory, and also to disable the libguestfs tests. To do that, I have a ~/.rpmmacros file that contains:

%_topdir	%(echo $HOME)/rpmbuild
%_smp_mflags	-j5
%libguestfs_runtests   0

You may wish to adjust %_smp_mflags. A good value to choose is 1 + the number of cores on your machine.

I’ll assume at this point that the reason you want to rebuild libguestfs is to apply a patch (otherwise why aren’t you using the binaries we supply?), so first let’s unpack the source tree. Note I am running this command as non-root:

rpm -i libguestfs-1.28.1-1.55.el7.src.rpm

If you set up ~/.rpmmacros as above then the sources should be unpacked under ~/rpmbuild/SPECS and ~/rpmbuild/SOURCES.

Take a look at least at the libguestfs.spec file. You may wish to modify it now to add any patches you need (add the patch files to the SOURCES/ subdirectory). You might also want to modify the Release: tag so that your package doesn’t conflict with the official package.

You might also need to install build dependencies. This command should be run as root since it needs to install packages, and also note that you may need packages from the repo linked above.

yum-builddep libguestfs.spec

Now you can rebuild libguestfs (non-root!):

rpmbuild -ba libguestfs.spec

With the tests disabled, on decent hardware, that should take about 10 minutes.

The final binary packages will end up in ~/rpmbuild/RPMS/ and can be installed as normal:

yum localupdate x86_64/*.rpm noarch/*.rpm

You might see errors during the build phase. If they aren’t fatal, you can ignore them, but if the build fails then post the complete log to our mailing list (you don’t need to subscribe) so we can help you out.


Filed under Uncategorized

8 responses to “How to rebuild libguestfs from source on RHEL or CentOS 7

  1. I built it on openSUSE last week – do I get a prize?!

    • rich

      I think 🙂 However OpenSUSE ships libguestfs, and in fact one of the SUSE guys is active upstream, so probably you should just use their package.

  2. siddhesh


    Guest mount is not working in libguestfs-1.28.1-1.55.el7.
    It fails to mount ntfs partition. Issue is on centos 7.2.

    But older version rpm can easily mount the windows disk without any issue.

    With libguestfs-1.28.1-1.18.el7. rpm ntfs mount works as charm but with libguestfs-1.28.1-1.55.el7 ntfs mount fails on centos 7.2.

    Please help me with the same.

    This command work on libguestfs-1.28.1-1.18.el7 but dose not work on ibguestfs-1.28.1-1.55.el7 ntfs mount fails on centos 7.2

    guestmount -a test.qcow2 -i –rw /mnt

  3. siddhesh


    Thanks for your help. But let me know the last version of rpm which will fix my requirement so i can compile the new rpm.

    Please guide me to fix my issue.

  4. siddhesh


    Sir god bless you thank for your help i had read it from the stable source and also figured it out.

    Really appreciate you for the help.

  5. Jonathan Wright

    I found this immensely helpful! Thanks!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.