Migration to Linux: VMs: Migrating from VMWare Fusion

From Wurst-Wasser.net
Revision as of 14:34, 23 August 2023 by Heiko (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

You are here: /Migrating from macOS to Linux/Migration to Linux: VMs: Migrating from VMWare Fusion


https://annvix.com/blog/converting-a-vmware-fusion-virtual-machine-to-kvm

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

In my case:

WroDos-MacBook-Pro:Library heiko$ ./vmware-vdiskmanager -r /Volumes/Daten\ HD\ \(Portable\ Samsung\ 2TB\)/Users/heiko/Documents/VMWare\ Machines\ \(ausgelagert\)/Windows\ XP\ Professional.vmwarevm/Virtual\ Disk.vmdk -t 0 ~/Desktop/WindowsXP.vmdk
VixDiskLib: Failed to initialize PhoneHome library.
Creating disk '/Users/heiko/Desktop/WindowsXP.vmdk'
  Convert: 100% done.
Virtual disk conversion successful.WroDos-MacBook-Pro:Library heiko$ ./vmware-vdiskmanager -r /Volumes/Daten\ HD\ \(Portable\ Samsung\ 2TB\)/Users/heiko/Documents/VMWare\ Machines\ \(ausgelagert\)/Windows\ 7.vmwarevm/ -t 0 ~/Desktop/Windows7.vmdkApplications/          Windows 7-0-s006.vmdk  Windows 7-0-s012.vmdk  Windows 7-0.vmdk       appListCache/          vmware-2.logWindows 7-0-s001.vmdk  Windows 7-0-s007.vmdk  Windows 7-0-s013.vmdk  Windows 7.nvram        caches/                vmware.logWindows 7-0-s002.vmdk  Windows 7-0-s008.vmdk  Windows 7-0-s014.vmdk  Windows 7.plist        quicklook-cache.png    Windows 7-0-s003.vmdk  Windows 7-0-s009.vmdk  Windows 7-0-s015.vmdk  Windows 7.vmsd         startMenu.plist        Windows 7-0-s004.vmdk  Windows 7-0-s010.vmdk  Windows 7-0-s016.vmdk  Windows 7.vmx          vmware-0.log        
Windows 7-0-s005.vmdk  Windows 7-0-s011.vmdk  Windows 7-0-s017.vmdk  Windows 7.vmxf         vmware-1.log           
WroDos-MacBook-Pro:Library heiko$ ./vmware-vdiskmanager -r /Volumes/Daten\ HD\ \(Portable\ Samsung\ 2TB\)/Users/heiko/Documents/VMWare\ Machines\ \(ausgelagert\)/Windows\ 7.vmwarevm/Windows\ 7-0.vmdk -t 0 ~/Desktop/Windows7.vmdk
VixDiskLib: Failed to initialize PhoneHome library.
Creating disk '/Users/heiko/Desktop/Windows7.vmdk'
  Convert: 3% done.

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.