Convert qcow2 to vmdk and make it ESXi 6.0 Compatible
Asked Answered
F

3

14

I am currently working on VMWare virtualization; I am trying to make a converted image from qcow2 to vmdk work with ESXi Server 6.0.

I have myImage.qcow2 with a disk which is thin provisioned for 300GB.

I used the image converter tool qemu with the following command

qemu-img convert -f qcow2 myImage.qcow2 -O vmdk myNewImage.vmdk 

This command gives me a vmdk image which is only VMWare Workstation compatible. Therefore, in order to make it ESXi compatible I have to use the vmkfstools with the following command.

vmkfstools -i myImage.vmdk outputName.vmdk -d thin

The vmkfstools command gives me two files, an metadata.vmdk and the actual data.vmdk.

As mentioned above my disk is thin provisioned for 300GB and when I apply vmkfstools it expands the disk and gives me a size of 300GB.

Deploying the image through the vSphere Client works without any problem; however, for the purpose of this project I want to use the ovftool and doing so with such a large image is not feasible.

Is there a way for me to make my .vmdk ESXi compatible without vmkfstools expanding my image to 300GB?

Or Is there any other method for me to deploy those 300GB using the ovftool while the disk image is on the datastore, so that it doesn't have to be downloaded/uploaded through the deployment process?

I have been stuck on this for weeks and any help will be highly appreciated.

Fils answered 13/6, 2016 at 16:30 Comment(1)
After further investigation, I managed to fix the problem using qemu 2.6 by using the following tags in the image conversion: qemu-img convert -f qcow2 -O vmdk -o adapter_type=lsilogic,subformat=streamOptimized,compat6 SC-1.qcow2 SC-1.vmdkFils
S
11

FYI: This support has been added in Qemu 2.1 and above as per changelogs

qemu-img convert -f qcow2 -O vmdk -o adapter_type=lsilogic,subformat=streamOptimized,compat6 SC-1.qcow2 SC-1.vmdk
Swagman answered 17/8, 2016 at 21:10 Comment(1)
If the above command was not useful please try it: qemu-img convert -f qcow2 -O vmdk src.qcow2 dst.vmdkFraenum
L
4

This worked for me with VMware 6.7

The TL;DR is

qemu-img convert -f qcow2 -O vmdk -o subformat=streamOptimized source_qcow_image_path destination_path_to_vmdk

For example:

qemu-img convert -f qcow2 -O vmdk -o subformat=streamOptimized \
 CentOS-7-x86_64-GenericCloud-1503.qcow2 \
 CentOS-7-x86_64-GenericCloud-1503.vmdk

Update the vmdk version setting embedded in the converted image using this script:

* This is what actually worked for me *

printf '\x03' | dd conv=notrunc of=<vmdk file name> bs=1 seek=$((0x4))

For example:

printf '\x03' | dd conv=notrunc of=CentOS-7-x86_64-GenericCloud-1503.vmdk bs=1 seek=$((0x4))

source: https://kb.vmware.com/s/article/2144687

Leanora answered 26/2, 2020 at 15:4 Comment(1)
Is there a way to verify if the format is properly taken into account ? I still get "invalid disk type 22" when trying to boot from the vmdk file on ESXi 6.7. I'd like to avoid using vmkfstools as it's unavailable from linux and requires a lot of local space on the ESXi server doing the conversion.Negotiable
D
0

As @pj_gineste we had the error message Unsupported or invalid disk type 22 (or Invalid disk type 2), and none of the options in qemu-img or by converting with vmware-vdiskmanager could fix that. Storage adapter settings in the ESXi VM did not have an effect either.


VMWare provides an OVF tool (CLI tool, runs on Linux/Mac/Windows) which converts VMWare machines to OVF/OVA.

It requires a .vmx file along with the .vmdk file.

To create the initial (plain-text) .vmx file, one can create a new VM in VMWare Workstation with suitable ESXi hardware compatibility and use that VM’s .vmx file with the .vmdk file. We use that for a build pipeline which finally outputs an OVA. The pipeline first produces a VMDK with Yocto and qemu-img and then generates the OVA toghether with the pre-produced VMX file.

The .vmx file may need some edits:

  • For ESXi 6.7 compatibility, the virtualHW.version property needs to be set to 15 in the .vmx file. See VMWare Hardware Versions.
  • The path to the .vmdk file needs to be changed to the VMDK that should be converted, e.g. nvme0:0.fileName = "/path/to/image.vmdk. The parameter name depends on the storage type of the attached disk etc., so consult your own VMX file.
  • We had to remove the sound card altogether.
Dnieper answered 5/6 at 8:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.