Creating and Configuring Hyper-V Virtual Hard Disks (VHDs)
|Previous||Table of Contents||Next|
|Configuring Hyper-V Virtual Machines||The Hyper-V Virtual Machine Connection Tool|
In Creating Hyper-V Virtual Machines we looked at creating a Hyper-V Virtual Hard Disk (VHD) as part of the Create New Virtual Machine wizard process. Unfortunately, the ease of use of the wizard masks some powerful features of Virtual Hard Disks within Hyper-V. The purpose of this chapter, therefore, is to cover some of the more advanced features of Hyper-V virtual hard disk creation and configuration.
Creating Hyper-V Virtual Hard Disks
As previously covered, virtual hard disks can be created as part of the virtual machine creation process. To gain access to a wider range of disk configuration options, an alternative is to create the disk independently of the virtual machine, and then subsequently assign it to the virtual machine after the disk has been created.
New disks are created from the Hyper-V Manager (Start->Administrative Tools->Hyper-V Manager). Once Hyper-V Manager is running, select the desired Hyper-V host from the left hand panel and then click on the New->Hard Disk... option in the Actions panel. This will invoke the New Virtual Hard Disk wizard. If the welcome screen appears, click next to proceed to the Choose Disk Type screen as illustrated in the following figure:
Hyper-V supports three different types of virtual hard disk:
- Dynamically Expanding - Dynamically expanding virtual hard disks start small and then automatically expand to provide more capacity on an as needed basis up to a maximum size specified at creation time. Note that the dynamic feature only applies to expansion. In other words, the virtual hard disk will not automatically decrease in size when data is removed. Dynamic expanding virtual hard disks may, however, be compacted to free up unused space.
- Fixed - Fixed virtual hard disks are created at the size specified during the disk creation process. The size of fixed virtual hard disks can be altered using the Hyper-V Manager Edit Disk... action to launch the Edit Virtual Hard Disk Wizard.
- Differencing - Differencing is a concept which involves a parent disk and a child disk. The parent disk contains a baseline hard disk image with the operating system and perhaps a range of applications and data installed. Once this baseline parent disk is configured, a differencing disk is assigned as a child. When the virtual machine to which the disk is assigned runs, any changes made the baseline parent image are actually stored on the child differencing disk, leaving the parent disk unaltered. Multiple child disks may be assigned to a parent disk allowing multiple virtual machines to share the same parent disk. Differencing disks may also be chained together. The changes contained in a differencing disk may be merged into the parent disk. Alternatively, a new virtual hard disk may be created containing the merger of the parent disk and the child disk, thereby leaving the parent disk unaltered. When creating a differencing disk, the parent disk will need to be specified. The size of the differencing disk increases as space is required. Differencing disks may also be compacted to free up unused space (see the section below entitled Modifying Existing Hyper-V Virtual Hard Disks).
Once a disk type has been selected, click Next to specify a name and location for the virtual disk. Any location accessible to the host system may be used, or the default location accepted. Clicking Next proceeds to the Configure Disk screen shown below:
After selecting the initial size of the disk, the option is then provided to clone the image of a physical disk into the new virtual hard disk, allowing an existing operating system configuration to be duplicated on the virtual hard disk. A list of physical hard disk drives detected on the host system is provided for selection.
After clicking Next the summary screen is displayed. Clicking Finish initiates the disk creation process.
Modifying Existing Hyper-V Virtual Hard Disks
Once a Hyper-V virtual hard disk has been created, it can be modified in a variety of ways using the Edit Virtual Hard Disk Wizard. The wizard is loaded by launching the Hyper-V Manager wizard and clicking on the Edit Hard Disks... link in the Actions panel. If the optional welcome screen appears, click Next to proceed to the Locate Virtual Hard Disk screen. On this screen, specify the full path to the virtual disk .vhd file using the Browse button to navigate to the correct file. With the correct location specified, proceed once again with the Next button which will display the Choose Action screen. The options provided depend on the type of the specified virtual disk. The following figure illustrates the options provided for a dynamic expandable disk:
There are a total of five actions that can be performed on virtual hard disks as outlined in the following table:
|Compact||Available on dynamically expanding and differencing virtual hard disks, this option shrinks the size of the selected .vhd image file by removing unused space left behind after data is deleted from the disk. This option cannot reduce the size of non-NTFS formatted disks unless the unused space is previously filled with zeros.|
|Convert||Converts virtual hard disks to and from fixed and dynamic expandable types.|
|Expand||Increases the size of dynamic expandable and fixed virtual hard disks.|
|Merge||Merges the contents of the selected differencing virtual hard disk into the corresponding parent virtual hard disk. Alternatively, the contents of both the parent and child virtual hard disks may be merged into a new virtual hard disk, thereby leaving the original parent disk image unchanged.|
|Reconnect||Differencing disks must be associated with a parent virtual hard disk. This option allows a differencing virtual hard disk to be reconnected with a parent disk.|
Getting Information about a Hyper-V Virtual Hard Disk
Information about an existing Hyper-V virtual hard disk, such as the current size, maximum size, image file location and disk type, can be obtained at any time using the Hyper-V Manager. To achieve this, right click on the virtual machine to which the disk is assigned from the list of virtual machines displayed by Hyper-V Manager and click on the Settings... option of the resulting menu. In the Settings dialog, select the required hard drive from the Hardware panel which runs down the left hand side of the dialog. This will update the main panel to reflect the selected disk drive. In the Media section of this panel, click on the Inspect button to invoke the Virtual Hard Disk Properties dialog as illustrated below:
Removing a Virtual Hard Disk from a Hyper-V Virtual Machine
In order to remove a virtual hard disk from a Hyper-V virtual machine, launch the Hyper-V Manager, right click on the relevant virtual machine from the list and select Settings... from the menu. In the settings dialog, click on the hard drive to be removed in the Hardware panel located on the left hand side of the dialog, and then press the Remove button at the bottom of the main panel. Note that this process only disconnects the drive from the virtual machine, it does not delete the corresponding .vhd disk image.
Moving Hyper-V Virtual Hard Disks between IDE and SCSI Disk Controllers
When a virtual hard disk is assigned to a Hyper-V virtual machine it will be attached either to an IDE or a SCSI disk controller, depending on the configuration. Sometimes the guest operating system may dictate that the virtual hard disk be connected to a disk controller of different type to the one to which it is currently connected. Fortunately, a virtual hard disk may be moved between different disk controllers with relative ease.
For the purposes of this example, a virtual hard disk currently connected to an IDE controller will be moved to a SCSI controller. This task is performed from within the Hyper-V Manager tool. Begin by right clicking on the appropriate virtual machine from the list in the Hyper-V Manager and click on the Settings... menu option. Once the settings dialog appears check to see if a SCSI controller is already configured on the virtual machine. If no SCSI controller is currently configured, select the Add Hardware entry in the Hardware panel, select SCSI Controller from the list of available hardware devices and click on Add.
Select the SCSI controller from the Hardware list, ensure that Hard Disk is selected in the Add Hardware panel and click Add to display the Hard Drive settings panel. Use the Browse button in the Media section of the panel to navigate to the virtual hard disk .vhd file. Once the correct .vhd file has been specified, click on the Apply button to commit the configuration change.
With the disk now assigned to a SCSI controller, all that remains is to disconnect the drive from the IDE controller. To do so, select the disk entry beneath the IDE controller in the Hardware panel and click on Remove in the main hard disk settings panel. The disk with then be disconnected from IDE controller, leaving it accessible only through the SCSI controller.