[Libguestfs] Notes on getting libguestfs to work on Mac OS X

Richard W.M. Jones rjones at redhat.com
Sat Oct 19 22:16:29 UTC 2013


Updated - thanks to Pene on IRC.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Fedora Windows cross-compiler. Compile Windows programs, test, and
build Windows installers. Over 100 libraries supported.
http://fedoraproject.org/wiki/MinGW
-------------- next part --------------
libguestfs on Mac OS X (tested with libguestfs-1.24.0) [Oct 19 2013]:
----------------------------------------------------------------------

prerequisites:
--------------
- install osxfuse, download from: http://osxfuse.github.io
- install some dependencies using macports: sudo port install qemu cdrtools pcre augeas
- extract appliance to /usr/local/lib/guestfs/, download from: http://libguestfs.org/download/binaries/appliance/

patches:
--------
- libtool-kill-dependency_libs.sh: replace: chmod --reference="$output.tmp" "$output" -> chmod `stat -f "%p" "$output.tmp"` "$output"
[ Note: chmod option --reference doesn?t exist on mac, so to mimic its behaviour, we can use chmod and stat ]

- src/proto.c: replace: if (!(*xdrp) (&xdr, args)) -> if (!(*xdrp) (&xdr, args, 0))
- src/proto.c: replace: if (xdrp && ret && !xdrp (&xdr, ret)) -> if (xdrp && ret && !xdrp (&xdr, ret, 0))
[ Note: As noted in Apple?s xdr.h, if code invokes an xdrproc_t callback, it must be modified to pass a third parameter, which may simply be zero ]

- src/launch-direct.c: comment out: if (qemu_supports (g, data, "-nodefaults")) ADD_CMDLINE ("-nodefaults");
[ Note: This works around a qemu bug when using the -nodefaults parameter - "qemu: qemu_mutex_lock: Invalid argument" ]

- src/guestfs-internal-frontend.h: replace: #  define program_name "libguestfs" -> #  define program_name getprogname()
- gnulib/lib/error.c: replace: extern char *program_name; -> # define program_name getprogname()
[ Note: getprogname() on Mac OS X produces similar behaviour to program_invocation_short_name on Linux ]

- gnulib/lib/open_memstream.c: add new file, from patch at http://lists.gnu.org/archive/html/bug-gnulib/2010-04/msg00379.html, remove from it check for #if !HAVE_FUNOPEN (it exists on Mac OSX, but HAVE_FUNOPEN is not defined)
- gnulib/lib/stdio.in.h: add somewhere (for example, before #if @GNULIB_PCLOSE@): _GL_FUNCDECL_SYS (open_memstream, FILE *, (char **, size_t *));
- gnulib/lib/Makefile.in, replace: openat-die.lo -> open_memstream.lo openat-die.lo
- gnulib/lib/Makefile.in, replace: openat-die.c -> open_memstream.c openat-die.c
[ Note: Mac OS X lacks open_memstream and gnulib doesn't supply it. Note that open_memstream is part of POSIX, so this is a bug in OS X ]

- fuse/guestunmount.c: replace: execclp ("fusermount", "fusermount", "-u", mountpoint, NULL); -> execlp ("/sbin/umount", "umount", mountpoint, NULL);
[ Note: osxfuse file systems should be unmounted with the standard "umount" command, instead of the linux specific "fusermount" ]

- fuse/guestunmount.c: replace: execlp ("/sbin/fuser", "fuser", "-v", "-m", mountpoint, NULL); -> the following block:
    const char *cmd_prefix = "/bin/ps -p \"$(fuser -c ";
    const char *cmd_suffix = " 2>/dev/null)\" -o user,pid,comm 2>/dev/null";
    char *cmd = malloc (strlen(cmd_prefix) + strlen(mountpoint) + strlen(cmd_suffix) + 1);
    if (cmd) {
      sprintf (cmd, "%s%s%s", cmd_prefix, mountpoint, cmd_suffix);
      execlp ("/bin/sh", "sh", "-c", cmd, NULL);
      free (cmd);
    }
[ Note: fuser option -v doesn?t exist on Mac OS X, so to provide a similar output we can use: ps -p "$(fuser -c mountpoint 2>/dev/null)" -o user,pid,comm 2>/dev/null ]

- ruby/Makefile.in, replace: _guestfs.so -> _guestfs.bundle (2 occurrences)
- ruby/Rakefile.in, replace: _guestfs.so -> _guestfs.bundle (1 occurrence)
[ Note: rake apparently builds with extension .bundle on Mac OS X ]

configure:
----------
- use: ./configure --disable-appliance --disable-daemon --disable-probes --disable-php CFLAGS="-I/opt/local/include" LDFLAGS="-L/opt/local/lib" LIBS="-lintl" FUSE_CFLAGS="-I/usr/local/include/osxfuse/fuse -D_FILE_OFFSET_BITS=64" FUSE_LIBS="-losxfuse"
[ Note: regarding --disable-probes, it is needed as the configure script seems to enable probes by default on Mac OS X, and they don?t compile properly ]
[ Note: regarding --disable-php, you can remove it from options if you wish, but in Mac OS X "php-config --prefix" will always report /usr, even if your headers are not there. So if you build with php, make sure that either your /usr/include exists, or make it link to wherever your headers are before running configure ]

make, test & install:
---------------------
- make
- LIBGUESTFS_PATH=/usr/local/lib/guestfs/appliance make quickcheck
- sudo make install

use:
----
- to use guestfish: LIBGUESTFS_PATH=/usr/local/lib/guestfs/appliance guestfish
- to mount via osxfuse: LIBGUESTFS_PATH=/usr/local/lib/guestfs/appliance guestmount -o defer_permissions -o allow_other -a image -m device [--trace] mountpoint
[ Note: without the specified -o options for osxfuse, there seems to be a permissions problem on mounted images on Mac OS X (they are not writable) ]


More information about the Libguestfs mailing list