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.
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.
After some spec-studies, we now have a fully functional utility that has a potential of saving you a lot of time. But before we take a closer look at the new program, let us revisit the problem we are now creating by using it and let us try to differentiate various scenarios where the use of the program is appropriate and where it is not.
The basic and main problem of reusing the “second-hand” space on the underlying storage for new virtual disks is that if you do not zero-out the allocated space, you will end up with virtual disks that will most probably contain valid or partially valid data within the free space of the disk as seen from the virtual machine the disk will be attached to. This data can be easily recovered hence special care shall be taken to prevent this from happening.
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:
DON’T use the tool:
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!
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):
|Full or relative path to the file to be created, extended or examined.
|Disk size of the new VHDX or the target size of the VHDX to be extended. If no qualifier specified, the size is assumed to be in bytes, otherwise the qualifier denotes the multiplier. Supported qualifiers are MB, GB, TB. Examples: 100GB, 5TB. Minimal supported size is 32MB.
Mandatory, except for “display”-command.
|-b||--BlockSize||create||Block size of new new VHDx, in Megabytes.
Optional, default value: 32.
|-l||‑‑LogicalSectorSize||create||The virtual disk’s logical sector size, in bytes. Can be either 512 or 4096.
Optional, default value: 512.
|-p||‑‑PhysicalSectorSize||create||The virtual disk’s physical sector size, in bytes. Can be either 512 or 4096.
Optional, default value: 4096.
|-k||--KeepDeviceId||upgrade||Preserve SCSI device identifier (aka Page #83)
Optional, off by default.
|Switches verbose mode on and gives you some info on what was going on during the requested operation.
Optional, off by default.
|Switches debug mode on. Use when asked by our staff during troubleshooting.
Optional, off by default.
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.
vhdxtool.exe create -f test.vhdx -s 800MB
Creates a new VHDX, 800 megabytes big.
vhdxtool.exe create -f test.vhdx -s 2TB -b 64 -l 4096
Creates a new 4K-VHDX with the size of 2 terabytes.
vhdxtool.exe extend -f test.vhdx -s 80GB
Extends an existing VHDX to the size of 80 gigabytes.
vhdxtool.exe display -f test.vhdx
Displays internal information about an existing 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>
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.