Skip to content

Convert VM disks

qcow2 to vhd

  • vbox can import vhd and it takes less space
Bash
qemu-img convert -O vpc example-vm.qcow2 ur-new.vhd

stolen from

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)

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

Convert qcow2 to vmdk and make it VMware Workstation Player Compatible

Bash
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)

Bash
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)

Bash
qemu-img convert -f qcow2 -O vmdk -o adapter_type=lsilogic,subformat=streamOptimized,compat6 ubuntu.qcow2 ubuntu.vmdk
* https://linux.die.net/man/1/qemu-img

Convert qcow2 to Microsoft Hyper-V new vhdx format

Bash
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.)

  • https://docs.microsoft.com/en-us/azure/virtual-machines/linux/create-upload-generic#resizing-vhds
Bash
# 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
Bash
#!/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