Skip to content

fix(winpe): provision USB partitions with storage cmdlets#166

Merged
mchave3 merged 1 commit into
mainfrom
fix/usb-boot-image-provisioning
May 15, 2026
Merged

fix(winpe): provision USB partitions with storage cmdlets#166
mchave3 merged 1 commit into
mainfrom
fix/usb-boot-image-provisioning

Conversation

@mchave3
Copy link
Copy Markdown
Collaborator

@mchave3 mchave3 commented May 15, 2026

Summary

Fix USB boot media provisioning by replacing the DiskPart partitioning script with PowerShell Storage cmdlets and restoring detailed provisioning diagnostics in the media logs.

Fixes #165.

Reason

DiskPart can create a partition without reliably keeping a usable volume selected on fresh or inconsistent removable media. The original issue failed after select volume=<letter>, and the later USB test showed the same class of failure when format ran without an explicitly selected volume.

Using Storage cmdlets lets Foundry create partitions with explicit drive letters and format those volumes directly by drive letter, without depending on DiskPart focus state. The Storage cmdlets are quiet on success, so the script emits Foundry progress markers plus clean provisioning diagnostics that are streamed back into Foundry.log through the existing media progress pipeline. Native PowerShell verbose/progress streams are not forwarded because Windows PowerShell 5.1 serializes them as CLIXML in redirected streams.

Main changes

  • Replaced USB provisioning via diskpart.exe with an encoded PowerShell Storage script.
  • Clears, initializes, partitions, assigns drive letters, and formats BOOT/cache volumes through explicit Storage cmdlet calls.
  • Preserves GPT/MBR behavior, quick/full formatting, and MBR active partition handling.
  • Emits detailed USB provisioning progress for disk open, attribute prep, clear, initialize, BOOT creation/format, cache creation/format, and completion.
  • Logs clean provisioning diagnostics on successful runs via LogDetail, while keeping the visible operation status readable.
  • Added en-US and fr-FR translations for the new USB provisioning substeps.
  • Added regression coverage proving provisioning no longer invokes DiskPart, formats by explicit drive letter, reports streamed provisioning substeps, and forwards clean verbose details.

Testing notes

  • Verified the new regression test failed before the fix while provisioning still invoked diskpart.exe.
  • Ran dotnet test src\Foundry.Core.Tests\Foundry.Core.Tests.csproj --filter "FullyQualifiedName~WinPeUsbMediaServiceTests" --logger "console;verbosity=normal": 23 passed.
  • Ran dotnet build src\Foundry\Foundry.csproj --no-restore: succeeded, 0 warnings, 0 errors.
  • Ran dotnet test src\Foundry.Core.Tests\Foundry.Core.Tests.csproj --logger "console;verbosity=normal": 178 passed.
  • Ran git diff --check: clean, with Windows line-ending warnings only.

@github-actions github-actions Bot added tests Test coverage or test infrastructure change project: foundry-core Changes in the Foundry.Core shared business logic library labels May 15, 2026
@mchave3 mchave3 self-assigned this May 15, 2026
@mchave3 mchave3 force-pushed the fix/usb-boot-image-provisioning branch from 9ac2b64 to de02668 Compare May 15, 2026 22:09
@mchave3 mchave3 changed the title fix(winpe): format USB partitions before assigning letters fix(winpe): provision USB partitions with storage cmdlets May 15, 2026
Comment thread src/Foundry.Core.Tests/WinPe/WinPeUsbMediaServiceTests.cs Fixed
@mchave3 mchave3 force-pushed the fix/usb-boot-image-provisioning branch from de02668 to c1fcc9f Compare May 15, 2026 22:19
Comment thread src/Foundry.Core.Tests/WinPe/WinPeUsbMediaServiceTests.cs Fixed
Comment thread src/Foundry.Core.Tests/WinPe/WinPeUsbMediaServiceTests.cs Fixed
@mchave3 mchave3 force-pushed the fix/usb-boot-image-provisioning branch from c1fcc9f to 20a25e4 Compare May 15, 2026 22:24
@github-actions github-actions Bot added ui User interface or XAML changes project: foundry Changes in the Foundry desktop application labels May 15, 2026
new WinPeBuildArtifact
{
WorkingDirectoryPath = workspace.RootPath,
MediaDirectoryPath = Path.Combine(workspace.RootPath, "media"),
new WinPeBuildArtifact
{
WorkingDirectoryPath = workspace.RootPath,
MediaDirectoryPath = Path.Combine(workspace.RootPath, "media"),
@mchave3 mchave3 force-pushed the fix/usb-boot-image-provisioning branch from 20a25e4 to f38c4d9 Compare May 15, 2026 22:34
@mchave3 mchave3 force-pushed the fix/usb-boot-image-provisioning branch from f38c4d9 to a26a1d6 Compare May 15, 2026 22:45
@mchave3 mchave3 marked this pull request as ready for review May 15, 2026 23:00
Copilot AI review requested due to automatic review settings May 15, 2026 23:00
@mchave3 mchave3 merged commit 77ea052 into main May 15, 2026
10 checks passed
@mchave3 mchave3 deleted the fix/usb-boot-image-provisioning branch May 15, 2026 23:00
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a USB media creation failure (#165) caused by DiskPart losing volume focus between select volume and format. The provisioning step now invokes a PowerShell Storage cmdlet script (passed as an -EncodedCommand) that clears, initializes, partitions, and formats the BOOT and cache volumes by explicit drive letter. The script emits Foundry-prefixed progress/verbose markers that the service forwards through the existing IProgress<WinPeMediaProgress> pipeline (extended with a new LogDetail field), and adds localized substep strings (en-US, fr-FR) plus regression tests.

Changes:

  • Replace DiskPart-based BuildDiskPartScript with BuildPowerShellProvisioningScript, executed via IWinPeProcessOutputRunner so progress/verbose markers can be streamed to the UI.
  • Extend WinPeMediaProgress with LogDetail and surface it in StartMediaViewModel logging and new localized status strings.
  • Update unit tests to cover the new script generation, output forwarding, and confirm DiskPart is no longer invoked.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/Foundry.Core/Services/WinPe/WinPeUsbMediaService.cs Switch USB partition/format to PowerShell Storage cmdlets, stream progress/verbose markers, update failure diagnostics.
src/Foundry.Core/Services/WinPe/WinPeMediaProgress.cs Add LogDetail property for forwarded verbose diagnostics.
src/Foundry/ViewModels/StartMediaViewModel.cs Log LogDetail and map new provisioning substep statuses to resource keys.
src/Foundry/Strings/en-US/Resources.resw Add English strings for the new USB provisioning substeps.
src/Foundry/Strings/fr-FR/Resources.resw Add French translations for the new USB provisioning substeps.
src/Foundry.Core.Tests/WinPe/WinPeUsbMediaServiceTests.cs Replace DiskPart-script tests with PowerShell-script tests; add streaming/output forwarding regression coverage.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +368 to +370
"Clear-Disk -Number $diskNumber -RemoveData -RemoveOEM -Confirm:$false -ErrorAction Stop",
"Update-HostStorageCache -ErrorAction SilentlyContinue",
"Write-FoundryUsbVerbose 'USB partition table cleared and host storage cache refreshed.'",
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

project: foundry Changes in the Foundry desktop application project: foundry-core Changes in the Foundry.Core shared business logic library tests Test coverage or test infrastructure change ui User interface or XAML changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Failure to create USB media.

2 participants