This project is read-only.

Readonly VHD with NTFS

Jul 10, 2014 at 7:23 PM
I'm trying to create VHD with NTFS file system, which will able to mounted as readonly disc. I wrote a method, which creates VHD image with single directory in its root. Here's the code:
        private void BuildVhd(string targetVhd, long size, string lable)
            using (var f = File.Create(targetVhd))
            using (var disk = Disk.InitializeFixed(f, Ownership.None, size))
                BiosPartitionTable.Initialize(disk, WellKnownPartitionType.WindowsNtfs);
                using (var fs = NtfsFileSystem.Format(new VolumeManager(disk).GetLogicalVolumes()[0], lable))
                    fs.CreateDirectory("New Directory");
After creating and mounting image as readonly, it dislays as uninitialized and unpartioned. But if I mount this image without readonly checkmark, it initialize and works fine, and then it can be mount as readonly.
This is a problem for me because I need image, which sould work as readonly shortly.
I was trying to initialize MasterBootRecord, but it didn't help. In this case disc becomes initialized, but unformated (olso in first mount, after mounting without readonly it works).

Is it bug or I do somthing wrong? Can anybody help me?
May 24, 2015 at 6:11 AM
I have the same issue. I'm creating a vhd with the examples i have found in the forums. If i mount the VHD readwrite windows creates the system volume information guid properly and the volume mounts correctly. However, my goal is to have the vhd mount read-only for preservation purposes so when I attach read-only Windows always shows the vhd file system as uninitialized/unknown. I have exhaused all options trying to figure out a way to do this with discutils.... Is there something we are missing?

        using (System.IO.FileStream vhdStream = new FileStream(m_sFinalVHDFile, FileMode.Create, FileAccess.ReadWrite, FileShare.None))
            DiscUtils.VolumeManager vm = new DiscUtils.VolumeManager();
            DiscUtils.Partitions.BiosPartitionTable bpt = default(DiscUtils.Partitions.BiosPartitionTable);

            lEstimatedSize = Convert.ToInt64(30 * 1024 * 1024);
            using (DiscUtils.Vhd.Disk oDisk = DiscUtils.Vhd.Disk.InitializeFixed(vhdStream, DiscUtils.Ownership.None, lEstimatedSize))
                DiscUtils.Partitions.BiosPartitionTable.Initialize(oDisk, DiscUtils.Partitions.WellKnownPartitionType.WindowsNtfs);
                vm = new DiscUtils.VolumeManager(oDisk);

                DiscUtils.Ntfs.NtfsFileSystem.Format(vm.GetLogicalVolumes()[0], "My label");