linka-cloud / d2vm

Build Virtual Machine Image from Dockerfile or Docker image
Apache License 2.0
208 stars 31 forks source link

Build fails when trying to build .vhd #47

Closed Nojinverse closed 1 month ago

Nojinverse commented 7 months ago

Issue

from the documentation: d2vm build [context directory] [flags]

Flags: -o, --output string The output image, the extension determine the image format, raw will be used if none. Supported formats: qcow2 qed raw vdi vhd vmdk (default "disk0.qcow2")

but when trying to build a .vhd the build fails with

d2vm build . --verbose --password Test12345678 --output agent-image.vhd
...
qemu-img convert /tmp/d2vm/9a280bb5-8871-46bd-8c92-1f817e9c5334/disk0.d2vm.raw -O vhd /tmp/d2vm/9a280bb5-8871-46bd-8c92-1f817e9c5334/disk0.vhd
qemu-img: Unknown file format 'vhd'

Cause

The underlying qemu-img convert argument is vpc not vhd

see https://docs.openstack.org/image-guide/convert-images.html

Side note

it would be nice to be able to use additional options for qemu-img convert etc:

qemu-img convert agent-image.qcow2 -O vpc agent-image.vhd -o subformat=fixed,force_size
Adphi commented 7 months ago

Hi @Nojinverse, thanks for reporting this problem.

I may have made a typo when selecting formats for qemu-img (or missed an update), as the list of supported formats, as indicated by qemu-img --help, is as follows:

Supported formats: blkdebug blklogwrites blkreplay blkverify bochs cloop copy-on-read dmg file ftp ftps host_cdrom host_device http https iscsi iser luks nbd null-aio null-co nvme parallels qcow qcow2 qed quorum raw rbd replication sheepdog ssh throttle vdi vhdx vmdk vpc vvfat

There is no vhd but vhdx. Using vhdx as an extension in the d2vm ... command will not work because validation will reject it.

Would updating the format list to change vhd to vhdx and adding vpc solve your problem?

Image format conversion is only supported by convenience for the most common formats. For more advanced needs I think it's better to work in raw format and use qemu-img directly yourself.

Implementing the validation of these options would increase the maintenance work required for a relatively uncommon use.

MichaelF25 commented 4 months ago

@Adphi I am running into the same issue as @Nojinverse and since I also need VmWare vmdk output besides Hyper-V, I will go with raw output from d2vm (very very great tool by the way!) and calling qemu-img manually 2 times (1 for Hyper-V vhdx and 1 for VmWare vmdk).

vsysio-bgould commented 2 months ago

Hey gang. I had this issue as well and just created a PR that corrects it. https://github.com/linka-cloud/d2vm/pull/49