Skip to content

Instantly share code, notes, and snippets.

@bitroniq
Last active April 8, 2021 13:39
Show Gist options
  • Save bitroniq/59273e85c506175998a384d733b4e155 to your computer and use it in GitHub Desktop.
Save bitroniq/59273e85c506175998a384d733b4e155 to your computer and use it in GitHub Desktop.
Converting images with qemu-img convert

VM images

vGateway images extensions

  • .qcow2 - KVM type Virtual Machines
  • .vmdk - VMware and VirtualBox and ESXi
  • .vdi - VirtualBox
  • .vhdx - Microsoft Hyper-V
  • .vhd - Azure requires fixed size

Example commands Convert qcow2 to other formats

Convert for VirtualBox (.vdi)

qemu-img convert -O vdi ubuntu.qcow2 ubuntu.vdi

Convert qcow2 to vmdk and make it VMware Workstation Player Compatible

qemu-img convert -f qcow2 -O vmdk ubuntu.qcow2 ubuntu.vmdk

Convert qcow2 to vmdk and make it ESXi Compatible (doesn't work with VMware Workstation Player)

qemu-img convert -f qcow2 -O vmdk -o subformat=streamOptimized ubuntu.qcow2 ubuntu.vmdk

Covert for ESXi 6 - Create a VMDK version 6 image (instead of version 4) (doesn't work with VMware Workstation Player)

qemu-img convert -f qcow2 -O vmdk -o adapter_type=lsilogic,subformat=streamOptimized,compat6 ubuntu.qcow2 ubuntu.vmdk

Convert qcow2 to Microsoft Hyper-V new vhdx format

qemu-img convert -f qcow2 -O vhdx -o subformat=dynamic ubuntu.qcow2 ubuntu.vhdx

For Azure (VHD images on Azure must have a virtual size aligned to 1 MB.)

# requires qemu 2.6+
qemu-img convert -o subformat=fixed,force_size -O vpc MyLinuxVM.qcow2 MyLinuxVM.vhd

Example convert.sh script

root@aws1-cm-01:~/temp# cat convert.sh
#!/bin/bash
echo "vGateway Name: "
read vgwname
echo "provide link:"
read link
curl $link > ${vgwname}.qcow2
echo "Converting..."
qemu-img convert \
 -f qcow2 \
 -O vmdk \
 -o subformat=streamOptimized \
 ${vgwname}.qcow2 ${vgwname}.vmdk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment