Skip to content

Using libvirt with VMWare Fusion on Mac OS X

June 2, 2011

Even though its website doesn’t say so, recent versions of libvirt should work reasonably well on Mac OS X now. Let’s give it a shot at trying to get it to work with VMWare Fusion.

Now the fun starts:

$ virsh -c vmwarews:///session list
error: internal error vmrun utility is missing
error: failed to connect to the hypervisor
$ export PATH=/Library/Application\ Support/VMware\ Fusion/:$PATH
$ virsh -c vmwarews:///session list
error: Cannot find 'vmware' in path: No such file or directory
error: failed to connect to the hypervisor
$ export PATH=/Applications/VMware\ Fusion.app/Contents/MacOS:$PATH
$ virsh -c vmwarews:///session list

This starts the VMWare Fusion graphical interface. Not what we want. libvirt expects to run vmware -v to get the version, but that doesn’t work on the mac. Let’s hack the code:

int
vmwareExtractVersion(struct vmware_driver *driver)
{
    unsigned long version = 0;
    // hardcode version to 7.1 to try to trick libvirt into thinking we have workstation 7.1
    // char *tmp;
    const char *tmp = "7.1"; 
    int ret = -1;
    // virCommandPtr cmd;
    // char * outbuf = NULL;
    // const char * bin = (driver->type == TYPE_PLAYER) ? "vmplayer" : "vmware";
    // const char * pattern = (driver->type == TYPE_PLAYER) ?
    //             "VMware Player " : "VMware Workstation ";

    // cmd = virCommandNewArgList(bin, "-v", NULL);
    // virCommandSetOutputBuffer(cmd, &outbuf);
    // 
    // if (virCommandRun(cmd, NULL) < 0)
    //     goto cleanup;
    // 
    // if ((tmp = STRSKIP(outbuf, pattern)) == NULL) {
    //     vmwareError(VIR_ERR_INTERNAL_ERROR,
    //                 _("failed to parse %s version"), bin);
    //     goto cleanup;
    // }
    // 
    if (virParseVersionString(tmp, &version) version = version;
    ret = 0;

cleanup:
    // virCommandFree(cmd);
    // VIR_FREE(outbuf);
    return ret;
}

Recompile, reinstall, then

$ virsh -c vmwarews:///session list
error: internal error No yet handled value 'nat' for VMX entry 'ethernet0.connectionType'
error: failed to connect to the hyperviso

Looking at the code:

if (connectionType == NULL || STRCASEEQ(connectionType, "bridged")) {
    // set up ...
} else if (STRCASEEQ(connectionType, "hostonly")) {
    // FIXME
    VMX_ERROR(...); ...
} else if (STRCASEEQ(connectionType, "nat")) {
    // FIXME
    VMX_ERROR(...); ...
} else if (STRCASEEQ(connectionType, "custom")) {
   // set up ... (treat like bridged)
} else {
   VMX_ERROR(...); ...
}

It’s obvious a bridged network is what is supported. So let’s change all the VMs to use bridged networking….

$ virsh -c vmwarews:///session list
error: internal error Missing essential config entry 'ethernet0.networkName'
error: failed to connect to the hypervisor

cat >> VMXFILE <<END
ethernet0.networkName = ""
ethernet1.networkName = ""
END
$ virsh -c vmwarews:///session list
 Id Name                 State
----------------------------------
48627 VMNAME             running

$ virsh -c vmwarews:///session dominfo 48627
Id:             48627
Name:           VMNAME
UUID:           564d2021-a5e3-a0b2-8f55-0258afabbbec
OS Type:        hvm
State:          running
CPU(s):         1


Max memory:     1048576 kB
Used memory:    1048576 kB
Persistent:     yes

So it seems like with the above hacks, you can use libvirt with VMWare Fusion on Mac OS X.

On the other hand, I cannot get VirtualBox (4.0.8) working:

$ virsh -d 5 -c vbox:///session list
commands: "list"
(hangs at 100% CPU forever)
^C
About these ads

Comments are closed.

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: