I’ve been working with the Azure Disk APIs recently and noticed that there isn’t really an obvious way to create a VHD without calling the Add Data Disk API which automatically creates a blank VHD and attaches it to a machine.
It turns out that Azure VM disks are simply Page Blobs contained in blob service — which is great because you get all the good stuff from there like geo-replication, scalability and sunshine/rainbows.
At first it would seem that you can create a blank VHD by simply creating a blank PageBlob by calling the PUT Blob API. However its actually not that simple. Blobs are exactly like files, and have the same exact binary data as a file on your local disk. That being said you actually need to generate a valid VHD file. It turns out that a blank VHD is almost a blank binary file (one filled with all 0’s) with the exception of a Fixed VHD footer specified by the official Microsoft VHD file format spec.
This specification is about 10 years old, and comes in a trusty Word 2005 document. Nonetheless it is still accurate to the format today. I won’t bore you with the details so here’s a script that will generate the VHD file format footer given a valid VHD size (which should be in increments of 1GB).
Create A Blank VHD Without Attaching
To run the script below, just fill in the missing storage account, container & blob info then run:
pip install azure python blank_vhd.py