Tuesday, February 17, 2009 3:13 AM
Windows 7 Native VHD Support
One of my favorite features in our upcoming Windows 7 (and Server 2008 R2) release is the native support for VHDs, a.k.a. Virtual Hard Disks, the file format used by Virtual PC, Virtual Server and Hyper-V to represent virtual disks. In this post, I’ll show you the basics of this feature and how to use it. I won’t cover a sister-feature, boot from VHD, in this post but as we get closer to shipping Windows 7, I plan on blogging about that one too.
Why native VHD support?
A first question quite some readers might raise is why we’d build in support for the VHD format natively to Windows? As you might have figured by now, virtualization is becoming increasingly important for consolidation of servers, so that it just makes sense for the OS to have intrinsic understanding of one of virtualization’s core pillar: the disk format. Having such support helps for a variety of scenarios, ranging from maintenance of virtual disks, creation of new virtual disks for data, booting from them, etc. And you can expect the virtualization story to grow significantly over the next months and years to come.
This said, support for VHDs isn’t something unprecedented. A while back I blogged about VHDmount, a tool that shipped with Virtual Server 2005 R2 allowing you to take a VHD file and mount it to a drive letter, using a driver installed by the tool. Native VHD support can, besides its built-in nature, take all of this many steps further as explained above.
Virtual² Disk Service
The hub of disk administration on Windows is the Virtual Disk service. A bit of a historical misnomer, but understandable as “Prophetical Engineer” isn’t a job role at Microsoft (yet), as “virtual” here doesn’t refer to the VHD format in any way. VDS was introduced in Windows Server 2003 as a unification mechanism on top of different kinds of storage, therefore virtualizing the underlying software and hardware used for storage.
VDS is surfaced to users by means of various tools, like diskpart and the Disk Management MMC snap-in (diskmgmt.msc), but is made accessible through a set of COM interfaces (IVds*) as well. As usual in the world of software it helps to think about it in terms of the layered cake principle:
In this post I’ll cover the Disk Management MMC snap-in enhancements in Windows 7 as well as the enhancements made to diskpart, both to surface the new VHD support. In a later post, I’ll talk about API enhancements too (once we have a Windows 7 update for the Windows SDK published).
So, with the native VHD support in Windows 7, the Virtual in Virtual Disk Service is applicable twice, as now the VDS can be used to manage virtual hard disks or VHDs as well, hence my subtitle Virtual² Disk Service.
As this is a blog for geeks, let’s start on the dark side of the picture with Diskpart. As many of you know, Diskpart is centered around the idea of objects being managed. In the past, those objects were either disk, partition or volume. Now, in Windows 7, the object “type” vdisk has been added to that set. Quite a few commands know how to deal with vdisk objects (like create, select) while others are meant to be used for vdisks exclusively (like attach, detach). The picture below outlines the most important vdisk-aware or vdisk-specific commands:
Let’s go through the steps required to create a new vdisk, attach it and use it.
Step 1 – Create the VHD (only if you want a new disk)
Quite predictably, creating a VHD is carried out by the “create vdisk” command. Here’s the full syntax:
Notice the support to create fixed-size VHDs and expandable VHDs. Other than that, you can set the maximum size (which would become the preallocated space for a fixed-size VHD, and the maximum size for an expandable one) and create differencing disks by specifying the parent. I won’t dive into the advanced options, so let’s stick with the simplest configuration possible:
create vdisk file=”c:\temp\demo.vhd” maximum=1000
(Notice the default of “expandable” seems to be wrong currently. Actually the default is “fixed”, so you’ll get a file of the size specified.) Executing this command creates a new empty VHD in the specified location:
and triggers the installation of the VHD miniport driver (HBA = Host Bus Adapter, see the WDK for more information):
Step 2 – Select the virtual disk
Both when you’re creating a new VHD (see step 1) or using an existing one, the vdisk object needs to be selected prior to continuing with the next step of attaching the disk. This is done by the “select vdisk” command, pointing at the VHD to be selected:
I won’t go into merging this time, but if you’re using a differencing virtual disk and intend to merge it with its parent or parents, depth becomes a relevant setting in order to be able to merge till a certain parent level (e.g. root.vhd, diff1.vhd, diff2.vhd, diff3.vhd would require a depth of at least 4 to merge all the way up to the root VHD, allowing you to run the merge command to execute ((diff3 + diff2) + diff1) + root).
Anyway, selection is not a piece of art but let’s make sure using a list vdisk that “focus” has been moved to the selected virtual disk indeed:
That seems to have worked.
Step 3 – Surface/attach the disk
The “create vdisk” command is your VHD factory (much like an assembly line for physical harddisks), the “select vdisk” command is you unwrapping the newly manufactured disk and taking it in your electrostatic-free hands, and the “attach vdisk” command is you opening the case of the computer and connecting the thing to the motherboard:
Notice you should have focus on the vdisk first as outlined in the previous step. Upon executing “attach vdisk”, the focused object will be attached to the computer and appear in Device Management again (you’ll hear the “insert hardware” sound):
Although it appears in the list of devices…
… it’s still a virgin disk without any partitions, so you won’t see it in Windows Explorer yet:
You can verify the Virtual Disk Service knows about the VHD being “online” by executing “list vdisk” again:
Step 4 – Partitions and volumes (only if you’re creating a new disk)
The last part in creating a new virtual disks is nothing new compared to real physical disks: you need to partition them and assign drive letters.
Windows gently reminds you to format your new disk:
And after the usual procedure, we’re done:
Disk Management MMC snap-in
The above is the geeky way to deal with VHDs, but a more gentle way is present as well through the Disk Management MMC, diskmgmt.msc (also reachable for regular humans through Computer Management, assuming you can find that one :-)).
Let’s continue where we left off in the above: we already have an attached VHD, so Disk Management should show it. And indeed it does, even with a slightly different icon:
All the usual operations apply to deal with partitions and volumes, but obviously there should be some context-sensitivity for the fact we’re dealing with a VHD:
Let’s give it a try (you’ll hear the “remove hardware” sound when pressing OK):
How to create or attach a VHD? Plain simple again:
Most options of Diskpart (well, VDS to be precise) are surfaced through the UI:
Notice the drop-down with units of measure is prepared for the TB range, which could have been better given how optimistic we are in the “disk quota” management UI, but that’s a whole different story…:
And finally the “Attach VHD” isn’t too surprising either:
Recall though how it’s possible to attach a disk as virtual and how easy it is to do that through the UI. This is extremely handy if you simply want to inspect a VHD but avoid making any mistakes whatsoever.
| Digg It
Filed under: Windows 7