Tuesday, December 6, 2016

Migrating VMware Workstation Guests to KVM/qemu

I recently had the need to get one of my VMware Workstation guests (running CentOS 6.4) migrated to a KVM/qemu hypervisor environment. The VM was in the typical multiple file vmdk configuration that VMware Workstation uses.

Note: I've read that if you're migrating a Windows guest or a SCSI-originated guest (or something to that extent), you may get a BSOD or some other boot error. So this may not work for every case.

In summary, the process basically involves converting that multiple file setup into a single file, and then moving that single file into your storage pool for your KVM setup, from which you then import it. Of course, the devil is in the details, so...

Step 1 - Convert VMware multiple file VM into a single file
(note: if you have snapshots, it's best to delete those to ensure you're getting the latest image)
(note: your paths will vary)
# vmware-vdiskmanager -r /home/vm/vmware/c64/c64_disk.vmdk" -t 0 /home/c64.vmdk

During this, I got an error ("VixDiskLib: Invalid configuration file parameter.  Failed to read configuration file.") but I was able to continue on just fine. I assume this is about the VM's configuration, but since I was changing RAM amount and network stuff anyway, I didn't care.

Step 2 - Copy that single file to your storage pool / import location
(note: I'm doing it this way, as the next step is resource-intensive and my destination machine is faster - also, your paths will vary - also, I've setup my storage pool to not be the standard /var/lib/libvirt!)
# rsync -av /home/c64.vmdk [dest-machine]:/home/vm/c64/

Step 3 - Login to destination machine and convert the vmdk into a qemu-compatible format
(note: this will become your VM's main disk image file, so just put it in your pool where you plan on leaving it for the machine)
# qemu-img convert /home/vm/c64/c64.vmdk -O qcow2 /home/vm/c64/c64.img

Step 4 - Start virt-manager and import the VM
# virt-manager
- Create a new machine.
- Choose "Import existing disk image" option.
- Continue configuring it as necessary, and then boot it.

After all is said and done, you will need to tweak a few things (e.g. NIC/MAC, persistent net rules file, etc.), but you should basically be up and running.

Thursday, December 1, 2016

Headless CentOS 7 Virtualization Host: Part 1 - Host Installation & Setup

Here is how I setup a headless (no monitor) VM host on CentOS 7.2

Ensure your host's CPU can support virtualization (the result should be > 0):
# egrep -c '(vmx|svm)' /proc/cpuinfo
Install the KVM hypervisor and its necessary packages (this is competitive with vmware):
# yum install kvm libvirt virt-install qemu-kvm
Make sure the host's kernel is ready to perform NAT with the hypervisor for the VM guests. First we'll enable IP forwarding on the host:
# echo "net.ipv4.ip_forward = 1" | sudo tee /etc/sysctl.d/99-ipforward.conf
# sysctl -p /etc/sysctl.d/99-ipforward.conf
Then, we'll modify the network adapter's configuration to use a bridge adapter (in my case, I'm using eth1). Open the config file for editing, comment out everything IP-related (IP, gateway, DNS, etc.), and add a link to the bridge configuration file that we'll add next:
# vim /etc/sysconfig/network-scripts/ifcfg-eth1
BRIDGE=virbr0
Next, we need to create a bridge adapter configuration file and add the following lines (your info will probably be same as what you commented out above):
# vim /etc/sysconfig/network-scripts/ifcfg-virbr0 
DEVICE="virbr0"
TYPE=BRIDGE
ONBOOT=yes
BOOTPROTO=static
IPADDR="[YOURS]"
NETMASK="[YOURS]"
GATEWAY="[YOURS]"
DNS1="[YOURS]"
If possible, reboot the machine to ensure kernel modules and network settings load and initialize.

Finally, just verify your installation and configuration:
# lsmod | grep kvm
# ip a show virbr0
# virsh -c qemu:///system list