Skip to content

Fix VHD parsing - Take 2. #364

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 12, 2025
Merged

Fix VHD parsing - Take 2. #364

merged 3 commits into from
Aug 12, 2025

Conversation

cwize1
Copy link
Contributor

@cwize1 cwize1 commented Aug 8, 2025

Back in the Microsoft Virtual PC days, a VHD file's size was based on "Disk Geometry" instead of simple byte count. However, this method restricts the sizes that the disk can be. So, Hyper-V just ignores the "Disk Geometry" fields and uses the VHD's "Current Size" field instead. Unfortunately, qemu-img still by default outputs VHDs using "Disk Geometry". This generally means it has to round up the size. To make matters worse, the new disk size is almost never a multiple of 1 MiB, which can prevent this disk from being uploaded to Azure.

When Image Customizer uses qemu-img, it knows to pass an option that tells qemu-img to use "Current Size" instead of "Disk Geometry". Specifically, -o force_size=on. But if a user manually calls qemu-img, they might not know they need to do this.

This change adds logic to reject input VHDs that use "Disk Geometry" instead of "Current Size". This will make it easier to catch problematic disks earlier, instead of Image Customizer being blamed for the incorrect disk size.


Checklist

  • Tests added/updated
  • Documentation updated (if needed)
  • Code conforms to style guidelines

Back in the Microsoft Virtual PC days, a VHD file's size was based on
"Disk Geometry" instead of simple byte count. However, this method
restricts the sizes that the disk can be. So, Hyper-V just ignores the
"Disk Geometry" fields and uses the VHD's "Current Size" field instead.
Unfortunately, `qemu-img` still by default outputs VHDs using "Disk
Geometry". This generally means it has to round up the size. To make
matters worse, the new disk size is almost never a multiple of 1 MiB,
which can prevent this disk from being uploaded to Azure.

When Image Customizer uses `qemu-img`, it knows to pass an option that
tells `qemu-img` to use "Current Size" instead of "Disk Geometry".
Specifically, `-o force_size=on`. But if a user manually calls
`qemu-img`, they might not know they need to do this.

This change adds logic to reject input VHDs that use "Disk Geometry"
instead of "Current Size".
@cwize1 cwize1 requested a review from a team as a code owner August 8, 2025 19:09
@cwize1 cwize1 merged commit 5a01237 into main Aug 12, 2025
20 checks passed
@cwize1 cwize1 deleted the user/chrisgun/vhdFixTake2 branch August 12, 2025 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants