filename=$(basename "${1}") OVFNAME=${filename%.*} BLDISKNAME="${OVFNAME}-disk1.vmdk" SDDISKNAME="${OVFNAME}-disk2.vmdk" # Convert raw image to VMDK qemu-img convert -O vmdk -o 'adapter_type=lsilogic,subformat=streamOptimized,compat6' "${1}" "${BLDISKNAME}" #qemu-img create -f vmdk "${SDDISKNAME}" "32G" BLSIZE=$(du -b "${BLDISKNAME}" | cut -f 1) SDSIZE=$(du -b "${SDDISKNAME}" | cut -f 1) BLVIRTUALSIZE=$(qemu-img info "${BLDISKNAME}" --output json | jq -r '."virtual-size"') SDVIRTUALSIZE=$(qemu-img info "${SDDISKNAME}" --output json | jq -r '."virtual-size"') # Create VM configuration cat << _EOF_ > "${OVFNAME}.ovf" Virtual disk information The list of logical networks The bridged network A virtual machine ${OVFNAME} The kind of installed guest operating system Virtual hardware requirements Virtual Hardware Family 0 ${OVFNAME} vmx-21 hertz * 10^6 Number of Virtual CPUs 2 virtual CPU(s) 1 3 2 2 byte * 2^20 Memory Size 4096MB of memory 2 4 4096 1 0 SATA Controller sataController0 3 vmware.sata.ahci 20 1 0 USB Controller (XHCI) usb3 4 vmware.usb.xhci 23 1 0 USB Controller (EHCI) usb 5 vmware.usb.ehci 23 1 true serial0 6 21 1 1 true bridged VmxNet3 ethernet adapter on "bridged" ethernet0 7 VmxNet3 10 1 false sound 8 vmware.soundcard.ensoniq1371 1 1 false video 9 24 1 false vmci 10 vmware.vmci 1 1 0 disk0 ovf:/disk/vmdisk1 11 3 17 1 1 disk1 ovf:/disk/vmdisk2 12 3 17 1 A human-readable annotation Arc Loader _EOF_ # Create manifest file for automatic integrity check cat << _EOF_ > "${OVFNAME}.mf" SHA256(${OVFNAME}.ovf)= $(sha256sum "${OVFNAME}.ovf" | mawk '{print $1}') SHA256(${BLDISKNAME})= $(sha256sum "${BLDISKNAME}" | mawk '{print $1}') SHA256(${SDDISKNAME})= $(sha256sum "${SDDISKNAME}" | mawk '{print $1}') _EOF_ # Pack everything as OVA appliance for ESXi import rm -f "${OVFNAME}.ova" tar -cf "${OVFNAME}.ova" ${OVFNAME}.ovf ${BLDISKNAME} ${SDDISKNAME} ${OVFNAME}.mf rm -f ${OVFNAME}.ovf ${BLDISKNAME} ${SDDISKNAME} ${OVFNAME}.mf #gzip "${OVFNAME}.ova"