In the last weeks I started to migrate my virtual machines to KVM. Until now, I used on two Servers VMware Server 2.0 on Ubuntu, which caused many problems with Disk I/O’s and performance problems. Either way, I prefer Open Source software whenever possible. KVM and libvirt, which I use to manage KVM, is in a quite mature state nowadays.
To convert the VMware images I used this How-To. This worked quite well for most of my Virtual Machines. But several had snapshots or were split into 2GB files. This cant be handled by qemu-img. I converted the files to single, flat disk file first using vmware-vdiskmanager. In the end, I wanted to have pre-allocated (single file) anyway, because it provides best performance:
$ vmware-vdiskmanager -r Ubuntu.vmdk -t 0 Ubuntu-copy.vmdk |
This takes a lot of time, and doesn’t work for snapshoted files (I get always an error saying “parent of this virtual disk could not be opened”). Therefore I searched for another solution which I found using “vmware-mount”, an utility provided by VMware. Because I already set up a new Ubuntu Server Installation, I tried to avoid installing VMware Server 2 again. I had to copy some libraries around to start that utility direct out of the unpacked VMware directory.
$ tar xvzf VMware-server-2.0.2-203138.x86_64.tar.gz ... $ cp -R vmware-server-distrib/lib/lib/ vmware-server-distrib/bin/libdir/ |
After that, I mounted the source VMware disk (“-0000002” points to the current running snapshot).
$ sudo /home/user/vmware-server-distrib/bin/vmware-mount VirtMachine-0000002.vmdk /mnt |
Using that command generates a flat view to the VMware disk using FUSE. This disk is then mounted using “losetup”. By using the command “losetup”, we can figure out where that flat FUSE file lies on the filesystem. We see that the loopback device created by vmware-mount uses a offset, which is the effective beginning of the partition which was mounted. But we want the whole disk, with the partition table in it. So we can ignore this offset.
$ sudo losetup -a /dev/loop0: [0015]:2 (/var/run/vmware/fuse/6512247014271621407/flat), offset 32256 |
The file “/var/run/vmware/fuse/6512247014271621407/flat” contains the flat disk. This can be copied by just invoking the copy command “cp”. Its a good idea to unmount the disk before, to avoid writing new data to the disk during the copy process.
$ sudo umount /mnt $ sudo cp /var/run/vmware/fuse/6512247014271621407/flat /path/to/image/VirtMachine.raw |
This raw file can be used by KVM. If you want a qcow2 file, you can use qemu-img on the source file, and choose qcow2 as output…
If you move Windows Machines to KVM, also consider this Blog post to avoid BSOD’s. I had the 7b BSOD, and wiped VMware away already. I had to set the disk to IDE and use a Windows Server 2003 Disc to repair the installation (Using “Enter” to install, and Repair the detected installation with “R” then)
0 Comments.