SYSTOLA
VhdTool Is Dead, Long Live VhdxTool!
It has been a while since Microsoft introduced a new format for their virtual disk files - VHDX. Before that, a relatively simpler format, VHD, was widely used in different systems.

VHD was used in file servers, some iSCSI target servers, but most of all, of course, in Hyper-V servers. It was used and abused for different purposes also as a general container and even some backup systems supported backing it up as a whole and restoring individual items from its insides.

Note: there are two basic types of virtual disks: fixed and dynamically expanding. In this article, since we are talking production systems, only fixed-size disks are considered.

The main problem, though, was VHD-management. It was not so easy to create and manage VHD-files on Windows XP or Server 2003, unless you had MS iSCSI Target at hand. Windows 7 / Server 2008/R2 partially solved the problem by incorporating the management into WMI and also in GUI, thus providing creation and expansion possibilities from Powershell, Disk Management MMC and Diskpart.

But the main problem remained: if you wanted to create a virtual disk of a decent size, say hundreds of gigabytes and more, the process of creating those disks took just so much time even on fast hardware, let alone on slow machines or disks. The reason for this was a potential security risk of recovering old data on the newly allocated VHDs and the mitigation of this risk was by zeroing out the whole new disk-payload. See Ben Armstrong's blog on this.

Enter VhdTool

It took more than half a year for the guys at Microsoft to provide a tool for rapid creation of VHDs. This tool did not zero-out the new disk, thus it was lightning fast even while creating multi-gigabyte and terabyte-sized VHDs. Incidentally, the same functionality was provided by MS iSCSI Target server as part of Storage Server 2003 R2, but it was gone with the release of Storage Server 2008, if I remember it right. See the original announcement of the tool.

A couple of paragraphs later we will discuss the implications of using such tools for production, but what is more interesting now is that with the advent of Server 2012 and the new Hyper-V version, the old VHD format was abandoned in favour of the new and more reliable VHDX.

The new format has many benefits and is very convenient, but since its introduction, the Hyper-V community faced the comeback of the slow creation/resize. You can find numerous questions of the same nature all over the internet forums: how to speed up VHDX-creation. As you might have guessed, the aforementioned Vhdtool does not support VHDX-files, since the new format is completely different from VHD.

Working with virtual hard disks on the daily basis in our capacity as DaaS-Provider, our team, too, has faced this problem and, after having failed to find a successor for Vhdtool that would handle the new format, we decided to create the so much needed tool ourselves.
Always Safe And Never Sorry

It is not too difficult to differentiate between do's and don'ts while using the tool to create VHDXs. Let us look at some of these. For the sake of clarity end-user will mean, depending on the type of company you work for, either your colleagues or your customers (tenants).

DO use this tool:
  • in labs and testing environments without any restrictions
  • on the new hardware, meaning new, unused and unwritten underlying HDDs
  • on used HDDs if they all (!) were zeroed-out beforehand
  • for non-system VHDXs that will not be directly accessible by end-users (including admins) of the system, for example for SQL-Server or Exchange databases
  • for any internally used VHDXs that will never be exposed to end-users
DON'T use the tool:
  • for system VHDXs of the systems accessible by end-users
  • for non-system VHDXs of the systems accessible by end-users
  • for VHDXs accessible via SMB or other network protocols
  • for VHDXs that might be transferred to an end-user
  • for golden images of VHDXs for TS or VDI environments
  • for other VHDXs-templates that might end up being used in end-user systems
Once the scenario is clear to you and you find yourself on the DO-side, download a copy of VhdxTool, make sure your system has .NET 4.5 or greater installed, fire up an elevated command prompt or PowerShell console and let's start VHDXing!
Command Syntax, The System's Sin-Tax

There are five operations of the tool at the time of writing. Therefore four main modes of execution and one extra informational mode:

vhdxtool.exe create [options] - create a new VHDX
vhdxtool.exe extend [options] - extend an existing VHDX
vhdxtool.exe convert [options] - convert a dynamic VHDX to a static one
vhdxtool.exe upgrade [options] - convert a VHD to VHDX
vhdxtool.exe display [options] - view information about an existing VHDX

The options are as follows (use either short or long form):
BlockSize, LogicalSectorSize, PhysicalSectorSize are the same parameters you would usually provide to the New-VHD cmdlet. For normal operations you can just leave these parameters out and the default values will be used, these are fine for most cases. If you have newer 4K hard drives, you might need to tweak the sector size, in which case these parameters will be your friends. Also, consult these two resources on sector size choices: Microsoft support policy for 4K sector hard drives in Windows and Hyper-V Support for Large Sector Disks Overview.
Examples
Creates a new VHDX, 800 megabytes big.

vhdxtool.exe create -f test.vhdx -s 800MB
Creates a new 4K-VHDX with the size of 2 terabytes.

vhdxtool.exe create -f test.vhdx -s 2TB -b 64 -l 4096
Extends an existing VHDX to the size of 80 gigabytes.

vhdxtool.exe extend -f test.vhdx -s 80GB
Displays internal information about an existing VHDX.

vhdxtool.exe display -f test.vhdx
There are even more good news for those, who are used to the old syntax of Vhdtool: we've made our tool also compatible with vhdtool-syntax, so you can just type:

vhdxtool.exe /create <FilePath> <DiskSize>
vhdxtool.exe /extend <FilePath> <NewSize>
Conclusion

With VhdxTool you can now create virtual hard disks of any size with blazing speed. Whether you want a 10GB or 10TB VHDX - it does not matter, VhdxTool will need the same amount of time for any size, just provide enough space on the storage side.

VhdxTool requires .NET 4.5, but we assume you will run it on WIndows Server 2012/R2 most of the time, where this component should be already installed.

You should always observe the applicability of this tool before going into production and consider all the risks you may face. If in doubt, don't use the tool and go for a built-in solution, but if you know what you are doing - here is your time saver.

Happy VHDX'ing!