T7453: Enhance raw/qcow2 image creation #972
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Change summary
This pull request improves the reliability and robustness of the raw image generation process in raw_image.py, specifically addressing partition mapping and environment cleanup.
Types of changes
Description
Added support for kpartx to explicitly map partitions (EFI, root) from loop devices instead of relying on /dev/loopXp*, which can be unreliable.
Introduced disk_details as an attribute of BuildContext to persist partition info throughout the image creation process.
Enhanced BuildContext.exit() to unmount all mount points, remove kpartx mappings, and detach the loop device even in failure scenarios.
Fixed a potential crash when con.disk_details was missing in mount_image().
Added debug output for better observability (e.g., loop device in use, partitions mapped).
These changes improve compatibility across a variety of environments (containers, hosts with strict udev policies) and ensure a cleaner teardown process during builds.
How Has This Been Tested?
Flavor file: cloud-init.toml
packages = [
"cloud-init",
"qemu-guest-agent"
]
image_format = ["qcow2"]
disk_size = 10
[boot_settings]
console_type = "ttyS0"
Command:
sudo ./build-vyos-image --architecture amd64 --build-by "[email protected]" --reuse-iso vyos-1.5-rolling-*.iso cloud-init
Result:
Related Task(s)
T7453
Related PR(s)
Checklist: