11-15-2006 13:03 vs-admin

Increasing the size of a VHD in Virtual Server 2005 R2 SP1

 

When you create a Virtual Hard Disk (VHD), you must specify the maximum size for the disk.  If it is a fixed disk, the specified disk space is immediately allocated as a single file on the host drive.  If it is a dynamically expanding drive, an initial allocation is made as a single file on the host and the VHD file expands as data is written.  Eventually, if enough data is written, the disk grows to the maximum drive size that you originally set at creation time.  With Virtual Server RTM and R2, the default maximum size of a VHD was set to 16GB, but this could be changed to a larger size during disk creation.  With the large amounts of data typically generated these days, there are probably many VHD's out there reaching the default 16GB disk size. 

To avoid this potential issue, in Virtual Server 2005 R2 SP1 the default disk size is set to 127GB.  However, this new setting may potentially create a new issue.  If you create multiple dynamically expanding VHD's using the default size, you could quickly over subscribe the host drive if one or more VHD significantly expands because of new data being saved to it. 

Note:  Make sure to properly plan and configure your VHD size and effectively monitor your VHD sizes and storage devices to proactively resolve these types of issues.

Now what do you do if you need to expand the size of the VHD because it ran out of space?

Unfortunately, there is no silver bullet to magically fix this problem today.  The VHD maximum disk size cannot be modified once it is created.  When the VHD is originally created, internal definition of the disk is performed at that time.  This includes setting the disk header, the Block Allocation Table (BAT), and the disk footer.  The BAT is a table of absolute sector offsets into the file that refers to the assigned data blocks. The size of the BAT is calculated, and the number of entries is set based on the number of blocks needed to store the contents of the VHD when fully expanded. For example, a 2-GB VHD that uses 2 MB blocks requires 1024 BAT entries.

Although you could potentially create a tool to read a VHD format, determine the current configuration and BAT size, specify a new disk size, and finally create the VHD with the new size and BAT table with all current data blocks mapped to the new file, such a tool does not exist today.

Therefore, your next best option may be to do the following:

  1. Create a new VHD and set the maximum size needed.
  2. Using a disk imaging tool that allows you to expand the disk partition, image from the original VHD to the new VHD increasing the original partition allocation to accommodate the new VHD space requirements. You might have to fix the Master Boot Record (MBR) after you do this.
  3. Replace the original VHD with the new VHD.

This typically requires you to mount  the original and new VHD files to perform the imaging.  Virtual Server 2005 R2 SP1 makes this process much easier, and scriptable with the introduction of the VHDMount tool.  This tool will allow you to mount both the original and the new VHD from the host OS and perform the imaging without needing to boot into a virtual machine.

So, while the process is not as simple as running a tool to expand the existing disk, it is not a huge effort to undertake, but will require down time. 

For reference information on the VHD specification, go to http://www.microsoft.com/windowsserversystem/virtualserver/techinfo/vhdspec.mspx

 

Filed under: , , ,

Leave a Comment

(required) 
(required) 
(optional)
(required)