Tuesday, February 17, 2009 3:13 AM bart

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:

image

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.

 

Diskpart

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:

image

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:

image

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:

image

image

and triggers the installation of the VHD miniport driver (HBA = Host Bus Adapter, see the WDK for more information):

image

image

image

 

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:

image

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:

image

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:

image

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):

image

Although it appears in the list of devices…

image

… it’s still a virgin disk without any partitions, so you won’t see it in Windows Explorer yet:

image 

You can verify the Virtual Disk Service knows about the VHD being “online” by executing “list vdisk” again:

image

 

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.

image

Windows gently reminds you to format your new disk:

image

And after the usual procedure, we’re done:

image

 

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:

image

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:

image

Let’s give it a try (you’ll hear the “remove hardware” sound when pressing OK):

image

How to create or attach a VHD? Plain simple again:

image

Most options of Diskpart (well, VDS to be precise) are surfaced through the UI:

image

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…:

image

And finally the “Attach VHD” isn’t too surprising either:

image

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.

 

Happy VHD’ing!

Del.icio.us | Digg It | Technorati | Blinklist | Furl | reddit | DotNetKicks

Filed under:

Comments

# re: Windows 7 Native VHD Support

Tuesday, February 17, 2009 4:54 AM by seaJhawk

Great post, but please, please, please cover 'boot from VHD' or at least provide some good references.

# re: Windows 7 Native VHD Support

Tuesday, February 17, 2009 6:51 AM by Greg Duncan

Nice! Dude, you rock.

Thanks for all the time you spend on your posts. It's a good day when we get a Bart post... :)

Thanks again,

Greg

# Dew Drop - February 17, 2009 | Alvin Ashcraft's Morning Dew

Tuesday, February 17, 2009 7:27 AM by Dew Drop - February 17, 2009 | Alvin Ashcraft's Morning Dew

Pingback from  Dew Drop - February 17, 2009 | Alvin Ashcraft's Morning Dew

# re: Windows 7 Native VHD Support

Tuesday, February 17, 2009 8:32 AM by Mark

Any talk of native support for .ISO files. It would be nice to mount and unmount them from the Disk Manager.

# re: Windows 7 Native VHD Support

Tuesday, February 17, 2009 5:35 PM by Jack

Can you do a blog post on how you would use these features in anger? Would be nice to have some real life scenarious. Killer apps for this stuff if you will.

# re: Windows 7 Native VHD Support

Wednesday, February 18, 2009 2:22 AM by bart

Hi folks,

A few answers:

seaJhawk, Jack - turns out I'm writing this from a machine booting from a VHD :-). I'll talk about this in a subsequent post. The killer app there is I can swap to other demo VHDs quite easily without having a full virtualization stack like Hyper-V (not quite handy on a laptop). Diskpart is used in that scenario to be able to create the VHD and mount it during setup. More on that later.

Greg - my pleasure :-).

Mark - I totally agree that ISO file mounting would be a great feature. It turns out we have the bits in house through the unsupported (!) VCD ISO mount tool (download: download.microsoft.com/.../winxpvirtualcdcontrolpanel_21.exe). It's not unprecented such tools get into products at some point (think of robocopy.exe) but I can't confirm concrete plans to do so at the moment. I'll send your feedback to the storage teams (vote++).

Jack - another killer app is to add files to VHDs without booting the OS on it (if any) using virtualization software and having to copy the files over the virtual network or to set up folder sharing (e.g. just to copy a few demo files to your virtual machine). Similar reasoning applies to VHDs that are purely meant to keep data: preparing such a VHD can now be done by using it as a regular drive. And of course there's all the disk management operations you can do, such as defragmentation, again without requiring virtualization software to mount the VHD.

Any other things you folks want ot hear about? Shoot!

Thanks,

-Bart

# [转]使用win7/server2008的VHD支持特性

Wednesday, February 18, 2009 10:08 PM by new 维生素C.net()

# re: Windows 7 Native VHD Support

Friday, February 20, 2009 8:41 AM by Mark

Amen to native ISO support!  Bart -running the unsupported virtual  CD control panel is a PITA - (run XP compatibility, run as administrator - mounted drives only visible under administrator, and even then real flakey.). Arg.  I did find find a 3rd party solution from slysoft, but not sure I trust that site :) Again, if VPC can mount an ISO, why can't the native OS?

# Friday Links #39 | Blue Onion Software *

Friday, February 20, 2009 4:47 PM by Friday Links #39 | Blue Onion Software *

Pingback from  Friday Links #39 | Blue Onion Software *

# re: Windows 7 Native VHD Support

Monday, February 23, 2009 5:49 AM by Rick Webster

The Slysoft product, Virtual Clone Drive (VCD), is outstanding with very timely updates and support. It even works on Windows 7 (32 and 64 bit). It is free but I would still prefer that this was built into Windows. As an MSDN subscriber, I use VCD frequently. It not only supports ISO but also other common formats such as BIN and CCD. I tried to use Microsoft's Virtual CD Control panel but I agree, it was a PITA. It would be great if Microsoft could provide the features of Virtual Clone Drive natively, without requiring admin rights. It would also be useful if these virtual disks could be encrypted, requiring a password to mount them, similar to TrueCrypt. Maybe Microsoft should purchase this technology from Slysoft. MSDN subscribers would certainly welcome this feature.