Skip to content

Add conversion to VHDX - #77

Open
AkihiroSuda wants to merge 1 commit into
lima-vm:masterfrom
AkihiroSuda:vhdx
Open

Add conversion to VHDX#77
AkihiroSuda wants to merge 1 commit into
lima-vm:masterfrom
AkihiroSuda:vhdx

Conversation

@AkihiroSuda

Copy link
Copy Markdown
Member

What This PR Changes

Add vhdx.Writer for converting raw/qcow2 to vhdx:

f, _ := os.Create("a.vhdx")
defer f.Close()
w, _ := vhdx.NewWriter(f, img.Size(), vhdx.WriterOptions{})
_ = convert.Convert(w, img, convert.Options{})
_ = w.Close()

Spec: https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-vhdx/83e061f8-f6e2-4de1-91bd-5d518a43d477

Linked Issue (Required in most cases)

For:

How I Tested This

Used hack/compare-with-qemu-img.sh.
The script converts a qcow2 image to raw and vhdx, and compares them.

AI Usage

Assisted-by: Claude Fable 5.1 noreply@anthropic.com

Add vhdx.Writer, an io.WriterAt for a dynamic VHDX image that plugs
into convert.Convert. Payload blocks are allocated on the first
non-zero write, so zero and unallocated extents of the source become
PAYLOAD_BLOCK_ZERO entries. Unwritten parts of the file are kept as
holes by extending the file with Truncate when the target supports it.

The default block size is 1 MiB for disks up to 1 TiB (doubling beyond
that to keep the BAT at or under 8 MiB), smaller than the 8-32 MiB used
by qemu-img, since file systems that do not support sparse files, or
that fill small holes (APFS), allocate the unwritten part of every
touched block.

The example command gains `convert -O vhdx [-block-size N]`, and
hack/compare-with-qemu-img.sh gains a phase converting to VHDX and
comparing with qemu-img.

Spec: https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-vhdx/83e061f8-f6e2-4de1-91bd-5d518a43d477

Assisted-by: Claude Fable 5.1 <noreply@anthropic.com>
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
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.

1 participant