Click here to Skip to main content
12,702,596 members (32,541 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


2 bookmarked

How VHD Resizing Works?

, 20 Feb 2014 Ms-PL
Rate this:
Please Sign up or sign in to vote.
How VHD resizing works ?

IaaS Management Studio allows you to resize any VHD, how does it work under the hood?

To understand that, we need to take a look at the VHD format. Azure supports only fixed size VHD, which means that a VHD is as big as the maximum of data you need to save in it. In summary, if you have want a 30GB VHD, then, the logical size of your VHD will be 30GB, even if you actually use only 10GB.

This is not a problem in Azure since you are only billed for 512 bytes ranges that you really use. A new empty new 100 GB VHD in a blob will cost you in reality 512 Bytes of storage.

Why 512 Bytes? Because a fixed VHD only have a footer of 512 bytes at the end of the VHD file. The rest is raw data as you would find in any non virtual drive with MBR, partition and everything you are used to. Here is the format, diagram generated from classes taken from the excellent DiscUtils library.


So how do we resize the VHD?

Step 1: Retrieve the Current Footer and Build the New Footer

We open the blob, go to the end, read the bytes and parse it.
Then we modify the footer data structure in memory. We update the CurrentSize and OriginalSize of the VHD, make sure it rounds to the nearest whole MB.

We then update the geometry of the VHD disk. Some old system use CHS addressing to write data on a disk instead of a linear system (LBA addressing). This is just a way to reference a byte address with a Cylinder/Head/Sector tuple instead of a simple offset. Such addressing depends on the size of the disk (large disks have more head and cylinder).

However, modern OS do not use such addressing scheme anymore, things worked fine on windows and linux even if we do not update the Geometry.

Then, we update the checksum of the VHD, this allows OS to detect potential corruption of the VHD footer.


Step 2: Resize the Page Blob


Step 3: Clear the Old Footer and Set the New One at the End of the Blob


And now, you can enjoy a bigger drive!


This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


About the Author

Nicolas Dorier
Software Developer Freelance
France France
I am currently the CTO of Metaco, we are leveraging the Bitcoin Blockchain for delivering financial services.

I also developed a tool to make IaaS on Azure more easy to use IaaS Management Studio.

If you want to contact me, go this way Smile | :)

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170118.1 | Last Updated 21 Feb 2014
Article Copyright 2014 by Nicolas Dorier
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid