How to create NTFS VHD?
See original GitHub issueIn the Readme.md is a nice short example, how to create a FAT VHD. But how do I create an NTFS VHD?
So far I have
long diskSize = 300 * Sizes.OneMiB;
var vhdPath = Path.Combine(Path.GetTempPath(), Path.ChangeExtension(Path.GetRandomFileName(), "vhd"));
using (Stream vhdStream = File.Create(vhdPath))
{
var disk = DiscUtils.Vhd.Disk.InitializeFixed(vhdStream, Ownership.Dispose, diskSize); // What's the difference between Ownership.Dispose and Ownership.None?
BiosPartitionTable.Initialize(disk, WellKnownPartitionType.WindowsNtfs);
using (var ntfs = NtfsFileSystem.Format(disk.Content, "Virtual NTFS drive", disk.Geometry, disk.Partitions[0].FirstSector, diskSize / disk.SectorSize))
{
ntfs.CreateDirectory(@"TestDir\CHILD");
// do other things with the file system…
}
}
Before NtfsFileSystem.Format I have a VHD that seems to have a valid MBR and if I mount it, Windows tells me to format that new drive. After NtfsFileSystem.Format the MBR is gone and the Windows Management Tools tell me to initialize the drive with an MBR or GPT first.
Also, I commented it in the code snippet: What’s the difference between Ownership.Dispose and Ownership.None?
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
How to create and set up a virtual hard disk on Windows 10
How to create a VHDX or VHD on Windows 10 · Open Start. · Search for Disk Management and click the top result...
Read more >Create and Set Up New VHD or VHDX File in Windows 10
1 Open Disk Management (diskmgmt.msc). 2 Click/tap on Action in the menu bar, and click/tap on Create VHD. (see screenshot below).
Read more >How to create and set up new VHD or VHDX File in ...
Press Windows key + R. · Click Action in the menu bar, and click Create VHD. · On the dialog that pops up,...
Read more >Create vdisk
Creates a new virtual hard disk (VHD) file by using the available disk ... the VHD and format the partition(s) by using FAT,...
Read more >VHD/VHDX: How to Create a Dynamically Expanding ...
Open Disk Management · Create a Virtual Drive for Windows 10 · Set a name and location for your VDHX File · Create...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
this code (slightly changed) works for me fine. if i make a vhdx file i can double click to mount it in windows
I dont think the solution posted is working properly. It returns successfully and mounts, but if you look at it with disk/partition tools it doesnt have the same properties as a volume created with disk manager. For example, what ever is not correct about the drive is preventing Windows from allowing it to be Bitlocker’d. Has anyone else observed the same and have you found a solution?