Skip to content

Update Windows VM image generation scripts#383

Open
dinhngtu wants to merge 1 commit intomasterfrom
dnt/win-autoimg
Open

Update Windows VM image generation scripts#383
dinhngtu wants to merge 1 commit intomasterfrom
dnt/win-autoimg

Conversation

@dinhngtu
Copy link
Member

Add vm_compact.py for reducing XVA sizes to replace win-diskclone.sh
Remove scripts that are no longer used


vm_compact.py is a reimplementation of win-diskclone.sh that also manages the new VDI.

Since the image generation pipeline has changed, the install-autotest and unattend files are no longer used. They're not actively updated in this repo anyway.

@dinhngtu dinhngtu requested a review from a team as a code owner January 15, 2026 09:27
@dinhngtu dinhngtu force-pushed the dnt/win-autoimg branch 2 times, most recently from a6ebb86 to 5d8cefd Compare January 19, 2026 09:12
Add vm_compact.py for reducing XVA sizes to replace win-diskclone.sh
Remove scripts that are no longer used

Signed-off-by: Tu Dinh <ngoc-tu.dinh@vates.tech>
from lib.vbd import VBD
from lib.vm import VM

# Tool to compact Windows VMs and create test XVAs
Copy link

Choose a reason for hiding this comment

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

Suggested change
# Tool to compact Windows VMs and create test XVAs
# Tool to compress Windows VMs and create test XVAs


with tempfile.TemporaryDirectory() as mountpoint:
for vm_uuid in args.vm:
logging.info(f"Compacting VM {vm_uuid}")
Copy link

Choose a reason for hiding this comment

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

Suggested change
logging.info(f"Compacting VM {vm_uuid}")
logging.info(f"Compressing VM {vm_uuid}")

I am nitpicking: compact can be used but unsure it is used as widely as compress.

Copy link
Member Author

Choose a reason for hiding this comment

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

The script compacts the affected VMs, not just compressing it (due to the ntfsclone step, which omits free clusters from the destination VDI)

assert os.path.exists(orig_device_path)

logging.info(f"Cloning VDI {orig_vdi.name()}")
compact_vdi = orig_vdi.sr.create_vdi(f"{orig_vdi.name()}-compacted", orig_vdi.get_virtual_size())
Copy link

Choose a reason for hiding this comment

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

Suggested change
compact_vdi = orig_vdi.sr.create_vdi(f"{orig_vdi.name()}-compacted", orig_vdi.get_virtual_size())
compact_vdi = orig_vdi.sr.create_vdi(f"{orig_vdi.name()}-compressed", orig_vdi.get_virtual_size())

subprocess.run(["mount", orig_part, mountpoint], check=True)
try:
mountpath = pathlib.Path(mountpoint)
(mountpath / "pagefile.sys").unlink(missing_ok=True)
Copy link

Choose a reason for hiding this comment

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

will those files be created again ? if not i will just size to zero or replace empty contents

Copy link
Member Author

Choose a reason for hiding this comment

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

These are Windows temp files that will be automatically created again.

else:
logging.info(f"Cloning {orig_part} -> {compact_part}")
subprocess.run(
["dd", f"if={orig_part}", f"of={compact_part}", "bs=1M", "status=progress"], check=True
Copy link

Choose a reason for hiding this comment

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

do we need to set bs ? I think even a cat would work and the system figure out cache, it could save a bit of performance (or not)

Copy link
Member Author

Choose a reason for hiding this comment

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

Not really, I just used dd to print the cloning progress (compared to cat which is silent)

)

logging.info("Finalizing cloned VDI")
subprocess.run("sync", check=True)
Copy link

Choose a reason for hiding this comment

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

Usually i used to call sync serveral time, but I don't remember the reason

Copy link

@rzr rzr left a comment

Choose a reason for hiding this comment

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

I just made a couple of comments, if it helps

feel free to adjust the wording

@rzr rzr requested a review from a team January 20, 2026 11:33
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