I’ve been running an instance of my Nagios XI monitor in a VMware Fusion virtual machine on my (aging) Mac Pro. The other day I found a blog post on How I converted a VMware VM to KVM and since my new LAN server is a beefy 8-core AMD FX-8120 with 32GB RAM (as opposed to the 2 x 2.66GHz dual-core Xeon with 16GB RAM that is my 5(?) year old Mac Pro), I decided to try moving the VMware Fusion VM to running on my Linux server (Red Hat Enterprise Linux 6 with KVM).

Not to be redundant on the steps noted in the other blog post, but to be a bit more explicit, we’ll just go through the steps as I did notice a few errors (I’m assuming that blog post was written on some version of Ubuntu; I’m of course using a Red Hat Enterprise Linux 6 host).

The blog notes to run the qemu-img convert command on the non-wildcard vmdk file; however, I found that I needed to convert the multi-file image into a single disk image first, before it could be converted. This may be the case for VMware Workstation disk images as well, however keep in mind we’re using VMware Fusion 5 on OS X, so the tool we want is inside the VMware Fusion application bundle (specifically, we want the vmware-vdiskmanager program).

Before converting, however, I strongly recommend removing any existing snapshots of the virtual machine. The first time I did this, I got the original snapshot which had the guest running CentOS 5.6 (and I updated it to 5.9 this morning before starting this). So before converting anything, you probably need to remove any existing snapshots first. Then, on the mac, convert this multi-file image into a single image:

$ cd /Applications/VMware\ Fusion.app/Contents/Library
$ ./vmware-vdiskmanager -r ~/Documents/nagiosxi.vmwarevm/nagiosxi.vmdk \
    -t 0 ~/Desktop/nagiosxi.vmdk

This also gets rid of all of the extra VMware stuff like snapshots, etc. Copy this new vmdk file, as well as the vmx file in the container, to the Linux box.

Next, convert the new image file to QCOW2 format (the original blog post didn’t specify the output format; qemu-img defaults to a raw file which we don’t want, we want QCOW2).

#  qemu-img convert nagiosxi.vmdk -O qcow2 /srv/virt/images/nagiosxi.img
# ls /srv/virt/images/nagiosxi.img -l
-rw-r--r--. 1 root root 10737418240 Jan 27 08:33 /srv/virt/images/nagiosxi.img

Seems more reasonable. But we need to change permissions so that libvirt can read it:

# chown qemu:qemu /srv/virt/images/nagiosxi.img
# chmod 600 /srv/virt/images/nagiosxi.img

The next step is to use the vmware2libvirt script to convert the vmx file to an XML file for libvirt. Unfortunately, this only seems to ship with Ubuntu. Fortunately, we can grab the script from here. It’s just a python script with no dependencies, so run:

# python vmware2libvirt -f nagiosxi.vmwarevm/nagiosxi.vmx >~/nagiosxi.xml

Then we use virsh to import it. Unfortunately, in this step, virsh is looking for /usr/bin/kvm and the binary is actually installed as /usr/libexec/qemu-kvm, so we need to make a symlink first:

#  ln -s /usr/libexec/qemu-kvm /usr/bin/kvm
# virsh -c qemu:///system define ~/nagiosxi.xml

This will import the nagiosxi.xml file to /etc/libvirt/qemu/nagiosxi.xml.

The original blog post talked about using the virt-manager GUI to finalize things, and since I’m lazy and don’t know libvirt well enough to do all this on the commandline, we’ll do the same thing. Since that machine runs headless without a GUI, I need to ssh in as root with X forwarding and run virt-manager.

In the GUI, I can see my nagiosxi VM defined, so I select it and edit the virtual machine details. I need to remove the existing IDE Disk 1 (which points to the vmdk file) and add my converted image file. Essentially:

  • Add Hardware” -> “Storage” -> “Managed or other existing storage” -> Pick your new file
  • Select “Storage Format” -> Pick qcow2
  • Click “Finish”

You will also want to add a few more bits of hardware:

  • Serial: Device type: pty
  • Network: Host device: br0, Device model: virtio

In my case, there was no network device, and the serial console is useful for using commands like “virsh console” (but you have to setup the serial getty inside the VM for this to work).

Now you should be able to startup the new virtual machine. Once you have gotten it up and running, you’ll want to remove the vmware-tools that were installed.

Share on: TwitterLinkedIn

Related Posts





Stay in touch