Created
April 14, 2020 18:11
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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