This topic is a how to.
Please keep it as clear and simple as possible. Avoid speculative discussions as well as a deep dive into underlying mechanisms or related technologies.





Introduction

Virtual hard disks (VHDs) are a file type that acts like a hard disk. In previous versions of Windows, VHDs were used by virtual machines, such as those created by Microsoft Virtual Server 2005 or Microsoft Virtual PC. Additionally, Complete PC Backup in Windows Vista created a copy of the computer’s hard disk as a VHD disk image. Beginning with Windows 7, you can now mount VHDs exactly like a physical disk: by mounting a VHD, you can easily copy files to and from the virtual disk; additionally, Windows 7 can be configured to boot from a VHD.
You can create a VHD from either the Disk Management snap-in or the command line. After you create the VHD, you must attach it and then format it before you can use it, just like a physical partition. Another tool (not included in the operating system, but downloadable for free) that can allow you to create a virtual hard disk starting from a physical one is the Disk2VHD tool by Sysinternals.

Create a virtual hard disk from the Disk Management snap-in

From the Disk Management console, follow these steps:

  1. Right-click Disk Management and then click Create VHD. Follow the prompts that appear.
  2. Right-click the new disk and then click Initialize Disk. Click OK.
  3. From the DiskPart command-line tool at an elevated command prompt, run the create vdisk command and specify the file (to name the file) and maximum (to set the maximum size in megabytes) parameters. The following code demonstrates how to create a VHD file at C:\vdisks\disk1.vdh with a maximum file size of 16 GB (or 16,000 MB).

The new virtual disk is ready to be used, just like any other disk.

Create a virtual hard disk from the command line using Diskpart

From the DiskPart command-line tool at an elevated command prompt, run the create vdisk command and specify the file (to name the file) and maximum (to set the maximum size in megabytes) parameters. The following code demonstrates how to create a VHD file at C:\vdisks\disk1.vdh with a maximum file size of 16 GB (or 16,000 MB).



For additional options, run the command help create vdisk at the DiskPart command prompt. After you create a VHD, you must attach it, create a partition, assign it a drive letter, and format it before it can be used. The following script (which must be run within a DiskPart session) demonstrates how to do this.




Community Resources

Web Pages


See Also

  • Windows 7 resource Kit (Chapter 16, "Managing Disks and File Systems") by Mitch Tulloch, Tony Northrup, Jerry Honeycutt, Ed Wilson, and the Windows 7 Team at Microsoft (Microsoft Press, October 2009)

Other Languages

This article is also available in the following languages:

Italian (it-IT)