HyperV Replica–Virtual size of one or more virtual hard disks are different between Primary and Replica servers

|

Published on | Updated on December 30, 2020

3 Min. Read

Introduction

In Windows Server 2012 R2, the Hyper-V team added the ability to resize virtual hard disks attached to a vSCSI controller while the virtual machine is running.

For more information about resizing virtual hard disks, see Configure Online Virtual Hard Disk Resize.

With Online Virtual Hard Disk Resize, Hyper-V Replica took the benefit of this feature as well, so you can resize a virtual disk while the VM is running and been enabled for replication. There is no need to resync the VM after modifying the disk, and no need to delete and re-enable the replication!

Fix Error Event 29260, Hyper-V-VMMS

A classic example of this error is shown in the following screenshot, you resize the virtual disks for a VM on the Primary site without resizing the Replica site virtual disks as well.

HVR-VHDX-Size01

As you can see, the error message in the event viewer is a bit misleading.

[Cannot perform operation for virtual machine <VMName> as virtual size of one ore more virtual hard disks are different between primary and Replica servers. Delete and re-enable replication.]

In fact, we don’t need to delete and re-enable the replication as mentioned earlier in order to have the Primary and Replica VM back in Synch. The resync operation will not proceed as the two disks have different sizes.

The workflow to fix this error is the following:

Step 1.

On the primary site, select the virtual disk that you resized and use the Inspect option to check the current the size of the disk.

image

You can also use the Get-VHD PowerShell commandlet.

Get-VM -VMName <VMName> | Select-Object VMid | Get-VHD | Select-Object @{Expression = { $_.ComputerName}; Label="VMName"}, @{Expression = { ($_.FileSize / 1GB)}; Label="Current Disk Size (GB)"}, @{Expression = { ($_.Size / 1GB)}; Label="Max Disk Size (GB)"}

Step 2.

On the replica site, select the corresponding virtual disk and resize it using the Edit disk wizard or the Resize-VHD PowerShell commandlet to match the current size at the Primary site.

HVR-VHDX-Size07

Step 3.

Once you edit the disk at the replica site, you can resume the replication on the VM from the Primary site using Hyper-V Manager or the Resume-VMReplication PowerShell commandlet.

Get-VM -VMName <VMName> | Where-Object { $_.ReplicationHealth -eq "Critical" } | Resume-VMReplication -Resynchronize

HVR-VHDX-Size08

Step 4.

Once the replication is resumed, Event ID 29266 is logged under Hyper-V-VMMS logs as shown in the next screenshot.

image

Followed by “Resynchronization was successfully initiated for the primary virtual machine”. Event ID 32325.

image

Ensuring that the Replica disk is resized according to the Primary disk and resuming replication will be sufficient for resynchronization to continue.

Voilà! That’s all there is to it… You can also automate above steps using PowerShell. For this reason, I created the following nifty tool to help you can tackle and fix above error instantly.

<#
    .SYNOPSIS
    Hyper-V Replica Resize tool.

    .DESCRIPTION
    Hyper-V Replica Virtual Hard Disk Resize tool.

    .NOTES
    ===========================================================================
    File Name    : Resize-HVReplica.ps1
    Author       : Charbel Nemnom
    Version      : 1.0
    Date created : 15.August.2016
    Last modified: 18.August.2016
    Requires     : PowerShell Version 4.0 or above
    OS           : Windows Server 2012, 2012 R2 and 2016 Hyper-V
    Module       : Hyper-V-PowerShell
    ===========================================================================

    .LINK
    To provide feedback or for further assistance please visit:
    
Cover Page
.EXAMPLE .\Resize-HVReplica.ps1 -primaryserver <PrimaryHost> -replicaserver <ReplicaHost> -VM <VMName> This example will get the VM information from the Primary site and Replica site, Then find the right disk, and resize it to match the primary VM virtual disks. #> [CmdletBinding()] param ( [Parameter(Position=0,Mandatory=$true,HelpMessage = 'Primary Server')] [Alias('PrimHV')] [String]$primaryserver, [Parameter(Mandatory=$true,HelpMessage = 'Replica Server')] [Alias('RepHV')] [String]$replicaserver, [Parameter(Mandatory=$true,HelpMessage = 'VMName')] [Alias('VMName')] [String]$VM ) # Get VM info from the Primary and Replica site Write-Verbose "Get VM info from the Primary and Replica site" $HVRinfo = Invoke-Command -ComputerName $primaryserver, $replicaserver -ScriptBlock { Get-VM -VMName $Using:VM | Select-Object VMid | Get-VHD } $priminfo = $HVRinfo | Where-Object {$_.PSComputerName -eq $primaryserver} $replinfo = $HVRinfo | Where-Object {$_.PSComputerName -eq $replicaserver} $CountedVHDs = $priminfo.Count for ($i=0; $i -lt $CountedVHDs ; $i++) { if($priminfo.Size[$i] -ne $replinfo.Size[$i]) { # Find the right disk, and resize it to match the primary site Write-Verbose "Connect to Replica site " Invoke-Command -ComputerName $replicaserver -ScriptBlock { param ($replinfo,$priminfo,$VM) # Resize the disk on the replica site Resize-VHD -Path $replinfo.Path -SizeBytes $priminfo.size } -ArgumentList $replinfo[$i], $priminfo[$i], $VM Write-Verbose "Resize the virtual disk for VM: $VM on $($replinfo.PSComputerName[$i]) host to $($priminfo.size[$i]/1GB)GB." } Write-Verbose "Virtual Disk $($priminfo.Path[$i]) has the same size" }

This tool will help you to get the VM information from the primary and replica site, then find the right disk which is out of Synch and resize it to match the primary VM virtual disk(s).

HVR-VHDX-Size16

Hope this post has been useful and thank you for reading!

Cheers,
[email protected]

Previous

Step by Step: Secure and Control a PowerShell Direct Session with Just Enough Administration #HyperV #PowerShell #JEA

New VMware Migration Offer for Windows Server 2016 #HyperV #WS2016

Next

1 thought on “HyperV Replica–Virtual size of one or more virtual hard disks are different between Primary and Replica servers”

Leave a comment...

Leave a comment below...

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Subscribe to Charbel Nemnom’s Blog

Get the latest posts delivered right to your inbox

The content of this website is copyrighted from being plagiarized! However, you can copy from the 'Code Blocks'.

Please send your feedback to the author using this form for any 'Code' you like.

Thank you for visiting!