-1

I'm trying to create a bootable disk, e.g. a virtual disk or SD card, with the FAT32 file system from a C# code. It fails on two reasons:

  1. Formatting FAT32 partition with the standard windows tools format.exe or diskpart.exe as well with the PowerShell is only possible up to 32 GB.

Diskpart.exe:

create vdisk file=<path to vdisk file> maximum=33000
attach vdisk
create part primary
format quick fs=fat32
active
assign letter=<available drive letter>

Format.exe:

Format /FS:FAT32 <disk drive letter>

Powershell:

Format-Volume -DriveLetter <disk drive letter> -FileSystem FAT32

All these commands failed with the error "partition is too big"

=> Is there a way to create a large FAT32 partition programmatically? I know, there are applications like Rufus or AOMEI, which can do it. So this means, it is some how possible.

  1. I use the command line tool BootSect.exe to make the disk bootable on the BIOS systems:
System.Diagnostics.Process.Start("cmd.exe", "bootsect.exe /nt60 <disk drive letter> /mbr");

This tool seems however to be available only on command line. When calling from the C# application, the tool BootSect.exe is not available for runtime.

=> Is there a way to call the BootSect.exe from the C# application?

Thank you for any reply.

Best regards Igor

igor.br
  • 29
  • 7
  • 1
    Writing your own partitioning program is fairly risky. It is probably in the "if you need to ask how, don't do it" bucket. But do you really need to boot anything larger than 32Gb? afaik both windows and linux installers are much smaller than that. You should be able to create a 32Gb partition even if the media is much larger. – JonasH Apr 11 '23 at 07:55
  • I wanna create an installation SD card programmatically. The installation data may be > 32 GB. – igor.br Apr 11 '23 at 09:35
  • What about Powershell `Format-Volume -DriveLetter "YourDriveLetter" -FileSystem FAT32` – Charlieface Apr 11 '23 at 10:56
  • It also fails on > 32 GB – igor.br Apr 11 '23 at 20:56

1 Answers1

1

You can't. In Windows format you can't specify Allocation Unit large enough to cross 32GB limit because one backend developer had to quickly make temporary UI. And as we all know temporary solutions are most permanent.

You can theoretically override Allocation Unit Size but it requires full format, which is not supported on virtual disk you are testing with. Override trick also doesn't seem to work on Windows 11.

Windows solution is to just use exFAT, but its will likely cause fun problems for bootable drives so your mileage may vary.

Best CLI solution might actually be "just use Linux" or multi-partition drive, as there is lack of CLI tools for Windows for this task.

PTwr
  • 1,225
  • 1
  • 11
  • 16
  • As I mentioned, I know at least two UI tools, which can do it. So to format such partition manually is no problem. My task is to implement a C# tool, which should can do it too. But as I see, it seems not to be possible with the available tools. Nevertheless, thank you PTwr for your answer. – igor.br Apr 12 '23 at 17:36