Merge-VHD Powershell Command fails
-
Wednesday, August 08, 2012 1:44 PM
Hi,
I'm using Windows Server 2012 RC and running a highly available VM on Hyper-V cluster (using shared storage and CSV2.0). My VM has the only one differencing VHD. When I try to use Merge-VHD commandlet to merge the existing VHD I have a following output:
PS C:\> Merge-VHD -path 'C:\ClusterStorage\Volume3\vm1\vm1.vhd' -DestinationPath 'C:\ClusterStorage\Volume3\vm1\vm1merged.vhd'
Merge-VHD : Failed to merge the virtual disk.
The system failed to merge 'C:\ClusterStorage\Volume3\vm1\vm1.vhd': One or more arguments are invalid (0x80070057).
Failed to open attachment 'C:\ClusterStorage\Volume3\vm1\vm1.vhd'. Error: 'One or more arguments are invalid'.
If the merge succeeds, the system will still not be able delete 'C:\ClusterStorage\Volume3\vm1\vm1.vhd' due to internal errors: One or more arguments are invalid (0x800
70057).
A parameter that is not valid was passed to the operation.
At line:1 char:1
+ Merge-VHD -path 'C:\ClusterStorage\Volume3\vm1\vm1.vhd ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (Microsoft.Hyper...l.VMStorageTask:VMStorageTask) [Merge-VHD], Virtuali
zationOperationFailedException
+ FullyQualifiedErrorId : InvalidParameter,Microsoft.Vhd.PowerShell.MergeVhdCommandI created a new vhd that i'm using to merge to. I'm aware of UAC. I've got administrator rights. When I try to merge the vhd using hyper-v manager GUI, everything is fine. Could anybody help me please?
Jan Marek MCT | MCITP | MCTS
All Replies
-
Wednesday, August 08, 2012 2:18 PM
Hi Jan,
did you already look up the exact syntax for Merge-VHD (using "Get-Help Merge-VHD -full")?
I've got a feeling that you should define at least 2 VHD files; so it could be that the cmdlet is expecting a string array, instead of a single string.
regards,
Floris
Floris van der Ploeg
My blog: www.florisvanderploeg.com
If my post was helpfull, remember to click the "Vote as helpful" button, or use the "Mark as Answer" button -
Wednesday, August 08, 2012 2:50 PMModerator
Get-Help Merge-VHD tells me that hte VHD chan must not be attached when merge is initiated. The GUI might work around this.
The -example shows not creating a new VHD, but rather the child and the parent that you want to merge in to.
Extrapolating that example vm1.vhd would be the child and vm1root.vhd would be its parent that you want to merge in to.
You would not end up with a new VHD, but rather a flattened chain.
According to Help, if you only pass a child VHD then it is merged to its parent. The -DesitnationPath is used as a point in the chain to flatten to. So if you had a chain of 5 differencing disks you could choose the latest (as -Path) and difference 2 (as -DestinationPath).
The end result would flatten everying in between into the difference 2 disk. IF this didn't support chains in this way you would need to merge each VHD, one by one.
IF you want a new VHD from a chain - read out a snapshot into a new VHD - you would use Export-VMSnapshot.
Brian Ehlert
http://ITProctology.blogspot.com
Learn. Apply. Repeat.
Disclaimer: Attempting change is of your own free will. -
Thursday, August 09, 2012 9:43 AM
Hi Brian,
ok, I tried to run Merge-VHD with only one string, with no DestinationPath parameter. It works well. So the destinationpath parameter is not a path to the "new" vhd... So it means that there is no powershell equivalent to GUI option "Merge.. to a new virtual hard disk". Am I right?
Do you think there is any way how to do it? I mean - specify the "new" virtual hard disk... Maybe via WMI?
Jan Marek MCT | MCITP | MCTS
-
Thursday, August 09, 2012 3:28 PMModerator
Merge-VHD is built around the task of merging snapshots. Not flattening diferencing disks.
Export-Snapshot can take any point in a snapshot chain and give you a flat VHD. But, again, it is snapshot oriented. Not differencing disk oriented.
The New-VHD cmdlet will do what you are looking for.
Get-Help New-VHD -examples
Look at Example 3
It creates a new VHD and populates it with the data from a source disk. This source disk couldbe any disk in a differencing chain as the chain is 'read' into the new VHD.
Brian Ehlert
http://ITProctology.blogspot.com
Learn. Apply. Repeat.
Disclaimer: Attempting change is of your own free will.

