Skip to content

Instantly share code, notes, and snippets.

@vklachkov
Created April 14, 2020 18:11
Show Gist options
  • Save vklachkov/62519481bf80512270f662e42ce95e32 to your computer and use it in GitHub Desktop.
Save vklachkov/62519481bf80512270f662e42ce95e32 to your computer and use it in GitHub Desktop.
C# example which create vhdx disk and create empty ntfs volume using DiskUtils
using System.IO;
using DiscUtils;
using DiscUtils.Ntfs;
using DiscUtils.Partitions;
using DiscUtils.Streams;
using DiscUtils.Vhdx;
namespace App
{
internal class Program
{
public static void Main(string[] args)
{
var diskSize = 8000L * 1024 * 1024;
var asVhd = false;
using (var fs = new FileStream("demo.vhdx", FileMode.OpenOrCreate))
{
VirtualDisk destDisk = Disk.InitializeDynamic(fs, Ownership.None, diskSize);
BiosPartitionTable.Initialize(destDisk, WellKnownPartitionType.WindowsNtfs);
var volMgr = new VolumeManager(destDisk);
NtfsFileSystem.Format(volMgr.GetLogicalVolumes()[0], "Vol", new NtfsFormatOptions());
fs.Flush();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment