I often have the need to get more info on the .vhd and .avhd (Snapshots or Differencing) files. I use the below .vbs script to read the info from the file.
Here's a sample output:
C:\VMs\mergetest\>cscript vhdinfo.vbs C:\VMs\mergetest\mergetest\mergetest_23855B6F-070C-426D-82FC-94E2916391EC.avhdMicrosoft (R) Windows Script Host Version 5.8Copyright (C) Microsoft Corporation. All rights reserved.
VHDInfo.vbs v1.00 robertvi 091217Cookie .................... conectixFeature.................... 2Format .................... 65536Creator ................... winCreator Host OS............ Wi2kDisk Type.................. DifferencingSaved State................ 0
Dynamic InfoCookie .................... cxsparseParent .................... C:\VMs\mergetest\mergetest\mergetest.vhd
VHDSize 328191
Finished!
The most used info is Parent to identify the Parent of a snapshot
copy and paste the below and save as vhdinfo.vbs
Option Explicit WScript.Echo "VHDInfo.vbs v1.01 robertvi 091217"
' common consts Const TypeBinary = 1 ' getting file from args (no checks!) Dim arguments, inFile Set arguments = WScript.Arguments inFile = arguments(0) Dim inByteArray, disktype inByteArray = readBytes(inFile)
' Basic Footer
'ByteArray2Text(inByteArray) WScript.Echo "Cookie .................... " & ByteArray2Text(inByteArray,0,8)
WScript.Echo "Feature.................... " & ByteArray2DWORD(inByteArray,8)WScript.Echo "Format .................... " & ByteArray2DWORD(inByteArray,12)
WScript.Echo "Creator ................... " & ByteArray2Text(inByteArray,28,4)WScript.Echo "Creator Host OS............ " & ByteArray2Text(inByteArray,36,4)
disktype = ByteArray2DWORD(inByteArray,60)If disktype = 1 Then WScript.Echo"Disk Type.................. Reserved(deprecated)" End IfIf disktype = 2 Then WScript.Echo"Disk Type.................. Fixed" End IfIf disktype = 3 Then WScript.Echo"Disk Type.................. Dynamic" End IfIf disktype = 4 Then WScript.Echo"Disk Type.................. Differencing" End IfIf disktype = 5 Then WScript.Echo"Disk Type.................. Reserved(deprecated)" End IfIf disktype = 6 Then WScript.Echo"Disk Type.................. Reserved(deprecated)" End IfIf disktype >= 6 Then WScript.Echo"Disk Type.................. Unknown!" End If'bare with me, if it would be C i would have used switch
WScript.Echo "Saved State................ " & ByteArray2DWORD(inByteArray,84)
'Dynamic Info
If disktype = 3 Then
WScript.Echo vbCrLf & "Dynamic Info" WScript.Echo "Cookie .................... " & ByteArray2Text(inByteArray,512,8)
End If
If disktype = 4 Then
WScript.Echo vbCrLf & "Dynamic Info" WScript.Echo "Cookie .................... " & ByteArray2Text(inByteArray,512,8) WScript.Echo "Parent .................... " & ByteArray2UText(inByteArray,1536,512)
WScript.Echo vbcrlf & "VHDSize " & UBound(inByteArray)WScript.echo "Finished!"
private function readBytes(file) dim inStream ' ADODB stream object used set inStream = WScript.CreateObject("ADODB.Stream") ' open with no arguments makes the stream an empty container inStream.Open inStream.type= TypeBinary inStream.LoadFromFile(file) readBytes = inStream.Read() end function Function ByteArray2Text(varByteArray,offset,lenght) Dim strBuffer, lngCounter, strData strData = "" strBuffer = "" For lngCounter = offset to offset+lenght-1 strBuffer = strBuffer & Chr(255 And Ascb(Midb(varByteArray,lngCounter + 1, 1))) Next ByteArray2Text = strData & strBufferEnd Function
Function ByteArray2UText(varByteArray,offset,lenght) Dim strBuffer, lngCounter, strData strData = "" strBuffer = "" For lngCounter = offset to offset+lenght-1 Step 2 strBuffer = strBuffer & Chr(255 And Ascb(Midb(varByteArray,lngCounter + 1, 1))) Next ByteArray2UText = strData & strBufferEnd Function
Function ByteArray2DWORD(varByteArray,offset) Dim strBuffer, lngCounter, strData strData = "" strBuffer = "" For lngCounter = 0 to 3 ByteArray2DWORD = ByteArray2DWORD * 256 ByteArray2DWORD = ByteArray2DWORD + Ascb(Midb(varByteArray,offset+ lngCounter + 1, 1)) Next End Function
'*** End
Do you know of a way to change the offset of vhd?
We have some 2003 servers that need the offset changed, and I would rather not have to 'ghost' them all to new correctly aligned VHD's, that will take a long time.
Thanks!
Don't know if Í understand your Q correctly, But when you change the offset to the Data within the header, you would also need to move the data. So what is your expected saving from gost?
Maybe you could discard all header info, save it as a raw disk info and use vhdtool to create a new vhd of from that.
Cheers
Robert