Draft: add manual VHDX compaction command for stopped WSL distros (#40481)
* Add manual VHDX compaction command * Address compact command review feedback * Tighten compact command validation * Use existing user session interface for compact * Avoid holding instance lock during compact * Serialize compact with VHD operations * Restore package WiX trailing newline * Use locked distribution state for compact * Remove allow-unsafe parser restriction * Use conversion lock for compact * Format compact command source * Verify compact reclaims VHD space in test * Reject VHD compaction with clear error * Add compact telemetry * Show progress while compacting * Fix compact help locked token * Reduce compact test data cost * Update compact help text * Undo package.wix.in change per review feedback Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 37ad1fd7-a452-4056-a8cc-e91cf7870a60 * Address review: reword compact-not-supported message, merge scope_exits Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 37ad1fd7-a452-4056-a8cc-e91cf7870a60 * Align compact help text with shipped resw and fix locked token - HelpMessages test expected 'stopped WSL 2 distribution' but the resw help ships 'WSL 2 distribution'; drop 'stopped' so the test matches (compaction auto-terminates the distro, and sibling --resize/--move help omit it too). - Add missing trailing space to the --compact locked token in the help comment. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 37ad1fd7-a452-4056-a8cc-e91cf7870a60 * Trim the filesystem before compacting a distribution's VHD WSL2 does not mount ext4 with 'discard' and does not run fsck at boot, so blocks freed inside the guest stay marked as allocated in the VHD. A bare 'wsl --manage <distro> --compact' therefore reclaims very little space. Before compacting, attach the stopped distribution's VHD to the utility VM and run an offline 'e2fsck -f -y -E discard' on the raw device. This issues the same block-discard requests that 'fstrim' would on a mounted filesystem, so freed blocks are marked unused and the subsequent host-side compaction can reclaim them. Running e2fsck offline (rather than fstrim on a mount) reuses the plumbing already used by ResizeDistribution, needs no mount, relies only on e2fsprogs (guaranteed present in the utility VM), and also performs the filesystem check a reviewer asked for. The trim is best-effort: any failure is logged and does not abort compaction. The Compact unit test no longer runs 'fstrim' manually inside the guest, so it now validates that '--compact' performs the trim itself. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 37ad1fd7-a452-4056-a8cc-e91cf7870a60 * Pass explicit user token to s_OpenLxssUserKey * Remove stale VHD localization lock * Fix --compact localization lock delimiter * Default initialize distro configuration * Remove redundant compaction sharing violation handling * Remove redundant sparse setup from compact test * Simplify VHD compaction logging * Revert unrelated locked distribution rename * Remove redundant shutdown from compact test * Apply clang-format to compact changes * Fix compact command formatting --------- Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 37ad1fd7-a452-4056-a8cc-e91cf7870a60