Update to 0.10 creates corrupt VHDs

Jan 4, 2012 at 12:31 AM

After updating the binaries to 0.10 form 0.9. Any VHD I create now is labelled as corrupt when trying to attach it in Windows 7.

Am I missing something here ?

Coordinator
Jan 4, 2012 at 7:01 AM

It should work...

Can you post some sample code that you're finding creates corrupt disks? I can take a look.

 

Cheers,

Ken

Jan 4, 2012 at 8:57 AM

Below are the methods I am using.

Basically everything get started by calling InternalPerformPreProcessingActions. Hope it helps.

 



        Protected Overrides Function InternalPerformPreProcessingActions() As Boolean
            If Not IO.File.Exists(m_sFinalVHDFile) Then
                'Create and Format a new VHD File
                CreateVHD()
            End If

            ' now open it again
            m_oDiskStream = OpenVirtualNTFSStream()

            Return True
        End Function

        Private Function OpenVirtualNTFSStream() As DiscUtils.Ntfs.NtfsFileSystem
            Dim thedisk As DiscUtils.VirtualDisk = DiscUtils.Vhd.Disk.OpenDisk(m_sFinalVHDFile, IO.FileAccess.ReadWrite)
            Dim vm2 As New DiscUtils.VolumeManager(thedisk)
            Dim lvi2 As DiscUtils.LogicalVolumeInfo() = vm2.GetLogicalVolumes()

            Return New DiscUtils.Ntfs.NtfsFileSystem(lvi2(0).Open)
        End Function

        Private Sub CreateVHD()
            Using vhdStream As IO.Stream = IO.File.Create(m_sFinalVHDFile)

                'here i want to use the estimated size of the backup to judge the VHD limit.
                Dim lEstimatedSize As Long = CLng(m_stSweepInfo.Results.Scan.Size + (m_stSweepInfo.Results.Scan.Size * 0.3))
                Dim oDisk As DiscUtils.Vhd.Disk = DiscUtils.Vhd.Disk.InitializeFixed(vhdStream, DiscUtils.Ownership.None, lEstimatedSize)
                Dim bpt As DiscUtils.Partitions.BiosPartitionTable = DiscUtils.Partitions.BiosPartitionTable.Initialize(oDisk, DiscUtils.Partitions.WellKnownPartitionType.WindowsNtfs)

                Dim vm As New DiscUtils.VolumeManager(oDisk)
                Dim lvi As DiscUtils.LogicalVolumeInfo() = vm.GetLogicalVolumes()

                DiscUtils.Ntfs.NtfsFileSystem.Format(lvi(0), "LS_Disk")
            End Using
        End Sub

 

 

Coordinator
Jan 5, 2012 at 9:59 AM

Your code works for me - couple of things I noticed:

  • If I create a small disk (m_stSweepInfo.Results.Scan.Size = 4MB) using your code, then Windows shows an error if I try to mount the disk
  • Also, you're not disposing of all disposable objects (oDisk, the result of NtfsFileSystem.Format, etc) - that may be causing you problems

8MB seems to be a fairly sensible minimum size, that works in Windows.

 

Cheers,

Ken

Jan 10, 2012 at 11:57 AM

That's really weird, I've changed the code as seen below, but still 0.10 is creating corrupt VHD's. Would there be any issue with x86 or x64 modes ?

 

        Protected Overrides Function InternalPerformPreProcessingActions() As Boolean
            If Not IO.File.Exists(m_sFinalVHDFile) Then
                'Create and Format a new VHD File
                CreateVHD()
            End If

            ' now open it again
            m_oDiskStream = OpenVirtualNTFSStream()

            Return True
        End Function

        Private Function OpenVirtualNTFSStream() As DiscUtils.Ntfs.NtfsFileSystem
            Dim vm As DiscUtils.VolumeManager
            Dim lvi As DiscUtils.LogicalVolumeInfo()
            Dim oFS As DiscUtils.Ntfs.NtfsFileSystem

            m_oVDisk = DiscUtils.Vhd.Disk.OpenDisk(m_sFinalVHDFile, IO.FileAccess.ReadWrite)
            vm = New DiscUtils.VolumeManager(m_oVDisk)
            lvi = vm.GetLogicalVolumes()

            oFS = New DiscUtils.Ntfs.NtfsFileSystem(lvi(0).Open)

            vm = Nothing
            lvi = Nothing

            Return oFS
        End Function

        Private Sub CreateVHD()
            Dim lEstimatedSize As Long
            Dim vm As DiscUtils.VolumeManager
            Dim bpt As DiscUtils.Partitions.BiosPartitionTable
            Dim lvi As DiscUtils.LogicalVolumeInfo()

            Using vhdStream As IO.Stream = IO.File.Create(m_sFinalVHDFile)
                'here i want to use the estimated size of the backup to judge the VHD limit.
                lEstimatedSize = CLng(m_stSweepInfo.Results.Scan.Size + (m_stSweepInfo.Results.Scan.Size * 0.3))
                Using oDisk As DiscUtils.Vhd.Disk = DiscUtils.Vhd.Disk.InitializeFixed(vhdStream, DiscUtils.Ownership.None, lEstimatedSize)
                    bpt = DiscUtils.Partitions.BiosPartitionTable.Initialize(oDisk, DiscUtils.Partitions.WellKnownPartitionType.WindowsNtfs)

                    vm = New DiscUtils.VolumeManager(oDisk)
                    lvi = vm.GetLogicalVolumes()
                    DiscUtils.Ntfs.NtfsFileSystem.Format(lvi(0), "LS_Disk")
                End Using
            End Using

            vm = Nothing
            bpt = Nothing
            lvi = Nothing
        End Sub

        ''' <summary>
        ''' We dont have any specific InternalProcessFile code
        ''' </summary>
        ''' <remarks></remarks>
        Protected Overrides Function InternalPerformPostProcessingActions() As Boolean
            m_oDiskStream.Dispose()
            m_oDiskStream = Nothing

            m_oVDisk.Dispose()
            m_oVDisk = Nothing

            Return True
        End Function

Nov 5, 2014 at 4:48 AM
I've just upgraded from version 0.9 to version 0.11 and I am again getting corrupted VHD.

Files that worked fine in 0.9 do not work with 0.11 ... any ideas, my code is identical !
Nov 5, 2014 at 12:35 PM
Success!

I figured out that in .09 it did not matter what size your VHD was created as. However in 0.10 onward you must make sure your size is aligned to the nearest megabyte.

Probably the alignment depends on the configuration of the disk, Bytes per sector etc.