Convert Linux KVM machines to VMware ESXi5.x
We are preparing a migration from some KVM VM’s to our ESXi5.1 farm. We came up with the procedure below to be the fastest and most reliable way to convert these VM’s. Somehow VMware converter didn’t work properly with the linux disk formats or something.
1.1 Preparing the ESX Host
1.1.1 Create a local user account to be used by the Linux administrators
– Log in directly on the ESX host which will be used as a port to connect to the datastore.
– Select “Local Users and groups”
– Rightclick and choose “add new user” – Create a new user; for example “User = Linux”
– Go to the tab “Permissions”
– Select the right user and add it to the group “Administrator”
1.1.3 Connect storage
– Configure some datastore which will be used to upload the Linux disks to and to be used to connect to the VM
1.1.4 Enable SSH
– Enable SSH so your Linux administrators can access it directly and upload the the correct datastore
1.1.5 Locate VMFS location
-Connect to the ESX host trough SSH (you could use the ‘linux’ user to test if this works)
– Use ls –l /vmfs/volumes to see your datastores. For example you see :
ECA12331_M1_001 -> 51837959-2748d5fb-9914-001cc4dfb348
The path which will be used by your Linux adminstrators for uploading will be:
1.2 VM Preparations
– Create a VM on the correct datastore using a previously build Linux Template and the right specifications (CPU/Memory/NICS)
– When creating this VM, a folder will be created on the datastore according to the VM name like the example below.
~ # ls -l /vmfs/volumes/51837959-2748d5fb-9914-001cc4dfb348 drwxr-xr-x 1 root root 560 May 3 08:57 ISO for Xenapp6 drwxr-xr-x 1 root root 3080 Jun 23 10:26 VM262
2.1 Finding/converting Linux Disks
Check RHEV manager to locate the host which is running your VM. Log in to that host.
ps -ef | grep <VM>
This will return a long line
These are the disks mounted to the VM, if a VM has more disks, more entries will be shown. The last part of the line contains the LV, this can be checked on the Linux machine
[root@lin ~]# lvs | grep fa524f99-6567-40aa-ba78-b88be26793bb fa524f99-6567-40aa-ba78-b88be26793bb 46e85862-1f1d-4adc-9e21-d3ad2831e212 -wi-ao--- 15.00g
This contains a 15.00G disk (rootvg), because the VM is still running this logical volume is in use (-wi-ao—).To be sure we have the correct VM we will change the state of the LV when the VM is powered off.
[root@lin~]# lvs | grep fa524f99-6567-40aa-ba78-b88be26793bb fa524f99-6567-40aa-ba78-b88be26793bb 46e85862-1f1d-4adc-9e21-d3ad2831e212 -wi------ 15.00g
This LV isn’t active anymore and can be converted, make sure to check if there is enough space available.
Manually activate the logical volume:
lvchange -ay /dev/a8f28fa5-28ca-40af-a841-50ad69f37594/17ee3415-1d68-44fa-ae5a-4e92b08c1700
Then start the conversion, we used QEMU-IMG for this
qemu-img convert -f raw -O vmdk -o compat6 /rhev/data-center/2c4c4629-df2c-46f5-9ea7-72279d5f97b1/a8f28fa5-28ca-40af-a841-50ad69f37594/images/2c6ce7e2-ae16-49b3-9785-028c23158a39/17ee3415-1d68-44fa-ae5a-4e92b08c1700 /var/lib/libvirt/qemu/<VM>_rootvg.vmdk
After the conversion the Logical volume needs to be set to inactive using the command below:
lvchange -an /dev/a8f28fa5-28ca-40af-a841-50ad69f37594/17ee3415-1d68-44fa-ae5a-4e92b08c1700
2.2 Upload Linux disk to datastore
Upload the newly created VMDK using SCP
scp <VM>_rootvg.vmdk firstname.lastname@example.org:/vmfs/volumes/51837959-2748d5fb-9914-001cc4dfb348/<VM Name>
2.3 Connect VM to VMDK
– Go to “edit settings” at the VM
– Choose “add” -> “Hard Disk” -> “Use an existing virtual disk” -> “Browse”
Now browse to the datastore where the VMDK’s are uploaded and select the right disk to connect it to the VM. Repeat this for all the disks you want to add.
2.4 Power on the VM
Check if the VM powers on fine and starts.
If you receive disk errors, it’s possible something didn’t go right with the disks, probably a wrong format. You could use the command below (directly on the ESXi host) to inflate the disk to a proper ESXi format.
vmkfstools -i originaldisk.vmdk -d zeroedthick targetdisk.vmdk
I noticed that the disks I added are in a 2GB Sparse format, so a disk will be little chunks of 2 GB you can use the command above or a storage vMotion to make it to a single disk file.
2.5 vMotion to the right destination
You also can use a storage vMotion to let VMware inflate the disk