frenta - Fotolia
One major benefit of using a shared virtual hard disk is that you can deploy a guest failover cluster without needing to expose storage topology to virtual machines. The reason this is such a big benefit is because it reduces the time it takes to configure the shared storage for a guest cluster. Without the shared virtual hard disk feature, you would be required to work with the storage team to configure shared storages for guest clusters, which could take a considerable amount of time.
This tip will show how it is easy to deploy a guest cluster using the shared virtual hard disk feature of Hyper-V 2012 R2.
VMs that are going to be part of the guest cluster must have Windows Server 2012 or later OS installed. These VMs must be running on a Hyper-V 2012 R2 or later host. If you are planning to use Windows Server 2012 as a guest OS, make sure to upgrade Integration Services to Windows Server 2012 R2 version.
Virtual hard disks you are going to share between multiple VMs must be placed either on a CSV cluster configured on a block-level storage or a Scale-Out-File Server cluster configured on a file-based storage. If you try to enable sharing for a virtual hard disk that is not placed on either of those, you will see an error message as shown Figure 1.
As indicated in Figure 1, the virtual hard disk you are going to enable the sharing for is stored on a location that is not supported by the Shared Virtual Hard Disk feature. Before you enable sharing on a virtual hard disk, Hyper-V checks the underlying storage to ensure it supports the SCSI Persistent Reservation (PR) commands. A PR is a SCSI command that is used by the clustering to protect disks. When a disk is reserved, no other computers are allowed to access the disk. This is the basic functionality that Hyper-V would expect from the underlying storage before the sharing can be enabled. This is only possible if you implement shared storage.
As for using the shared virtual hard disk feature, the whole process is simple. All you need to do is create the VMs that are going to be part of the guest cluster, store VM configuration and virtual hard disk files to a shared storage location, enable virtual hard disk sharing on the property page of the VMs, verify sharing is enabled on virtual hard disks for all VMs and then build the guest cluster by installing the failover cluster feature inside the VMs.
Step 1: Creating VMs and assigning path to virtual hard disks
When creating VMs, make sure to specify the location for storing the VM configuration and virtual hard disk files as listed below:
- In case of a CSV cluster, specify C:\ClusterStorage\VolumeX where X represents the CSV volume number.
- In case of a Scale-Out-File Server cluster, use \\ServerName\ShareName as the path for storing VM configuration and virtual hard disk files.
It is recommended to create at least two virtual hard disks; one for installing the guest operating system and a second hard disk that will be shared between the VMs. The OS virtual hard disk can be either in VHD or VHDX format, but the data virtual hard disk that is going to be shared between multiple VMs must be in VHDX format. When creating the second virtual hard disk, make sure to attach VHDX to a virtual SCSI controller on all VMs that are going to be part of the guest cluster. This is because Hyper-V uses SCSI persistent reservation commands to enable sharing of a virtual hard disk between multiple VMs.
Step 2: Enabling Virtual Hard Disk Sharing
Hyper-V must be told to allow sharing of a virtual hard disk between multiple VMs and that is done by enabling a checkbox on the property page of VMs. To share a virtual hard disk, go the property of a VM and under SCSI controller, expand the virtual hard drive that you created and then go to Advanced Features. In the details pane, select "Enable virtual hard disk sharing" check box as shown in Figure 2 below and then hit "Apply."
Step 3: Attaching and enabling virtual hard disk sharing for remaining VMs
At this step, you are required to attach the VHDX file to a SCSI virtual controller on the remaining VMs and then select the "Enable virtual hard disk sharing" option. If you want to reduce the time it takes to enable virtual hard disk sharing for multiple VMs, consider using -ShareVirtualDisk parameter with Add-VMHardDiskDrive PowerShell cmdlet as shown in the below command:
- Add-VMHardDiskDrive -VMName <VM Name> -Path <Path to cluster storage> -ShareVirtualDisk
In above command, replace the <VM Name> with the name of VM that is going to be part of the guest cluster and <Path to cluster storage> with cluster storage path such as a CSV or SMB share.
To make sure VMs are configured to use the shared virtual hard disk and sharing is enabled on the virtual hard disk, execute the below command on each VM one by one:
- Get-VMHardDiskDrive -VMName <VM Name> | FT VMName, Path, SupportPersistentReservations
The value for "SupportPersistentReservations" must return "True" for the virtual hard disk that you intend to use for sharing. "True" indicates that the sharing is enabled for the virtual hard disk.
Step 4: Creating the guest cluster
The final step is to create the guest cluster. Before you create the guest cluster, you are required to bring the shared VHDX file online by using the Disk Management in one of the VMs and then format the volume. Once done, install the failover clustering feature and add VMs as cluster nodes.
Setting up virtual hard disk storage
How to manage virtual hard disk data with encapsulation