Skip to content

Instantly share code, notes, and snippets.

Created Jan 13, 2017
What would you like to do?
# Create an Azure compatible VHD from a VirtualBox VDI
# More info:
# And:
# Convert the image to raw
qemu-img convert -f vdi -O raw "$name.vdi" image.raw
# Get the size of the vdi
size=$(qemu-img info -f vdi --output json "$name.vdi" | \
gawk 'match($0, /"virtual-size": ([0-9]+),/, val) {print val[1]}')
# Calculate the size of the image to the nearest even integer because Azure is crazy
echo "Old size: $mb MB"
if [ $((mb%2)) -eq 0 ]; then increment=2; else increment=1; fi
mbincremented=$(($mb + $increment))
echo "New size: $mbincremented MB"
echo "Rounded Size = $rounded_size"
# Resize the image to the rounded size
qemu-img resize -f raw image.raw $rounded_size
# Convert the raw image to VHD
qemu-img convert -f raw -O vpc -o subformat=fixed,force_size image.raw "$name.vhd"
rm image.raw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment