[Libguestfs] [libguestfs] RFE: virt-builder option to auto-detect image format (#19)

Richard W.M. Jones rjones at redhat.com
Tue Dec 29 17:54:06 UTC 2015


On Mon, Dec 28, 2015 at 03:36:53PM -0800, Ryan Sawhill Aroha wrote:
> Hi there
>
> The repo definition at http://libguestfsorg/download/builder/index
> contains `format=raw` data for each template, eg:
>
> ```
> [centos-6]
> name=CentOS 66
> osinfo=centos66
> arch=x86_64
> file=centos-6.xz
> revision=6
> checksum=fc403ea3555a5608a25ad30ce2514b67288311a7197ddf9fb664475820f26db2bd95a86be9cd6e3f772187b384a02e0965430456dd518d343a80457057bc5441
> format=raw
> size=6442450944
> compressed_size=199265736
> expand=/dev/sda3
> notes=CentOS 66
> ```
>
> I haven't looked at the source, but it seems that `virt-builder`
> doesn't do anything with that metadata
>
> According to `man virt-builder`, it always assumes `--format raw`

The format parameter in the metadata and the --format option are
related, but different things.

The format= metadata tells virt-builder the format of the original
template (ie. centos-6.xz is raw format after decompression).  Image
format auto-detection is a security risk [although to be fair really
not in this particular case], and so it's better to specify the
format.

The --format parameter is what format the virt-builder end user would
like your final image to be.

So if format=raw and --format qcow2, then virt-builder knows it must
convert the image.  This is the code:
https://github.com/libguestfs/libguestfs/blob/master/builder/builder.ml#L310-L333

The --format command line parameter defaults to raw (and this is
documented in the manual).  It doesn't matter what the original
template format was.

> Why? I've built my own repo with all xz-compressed qcow images and
> it seems crazy to me that `virt-builder` can't auto-detect this;
> instead, I have to specify `--format qcow2` (or else vb converts
> them from qcow2 to raw)

So virt-builder is behaving as per specification above.

My initial thought was that we could have an `output_format=...' line
in the metadata.  However that has a couple of problems:

(1) Other metadata format like SimpleStreams doesn't support this.

(2) It breaks the virt-builder contract because we have documented in
the manual that the default output format (ie. if --format is not
specified) is raw.

However, read on ...

> Halp! Can we either change the default behavior to look for
> `format=qcow2|raw` in the template definition if `--format` isn't
> specified, or if you're unhappy changing the behavior, could we add
> `--format=auto`?

We couldn't call it "auto", since --format=auto is used in other
virt-* tools contexts to mean to do unsafe autodetection of the
format.

I don't mind if we called it something else, perhaps `--format=input'?
It just has to be a name that could never be used as a real disk
format (like 'qcow2' or 'vmdk').

The RFE process is described here:

http://libguestfs.org/guestfs-faq.1.html#how-do-i-propose-a-feature
https://bugzilla.redhat.com/enter_bug.cgi?component=libguestfs&product=Virtualization+Tools

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-builder quickly builds VMs from scratch
http://libguestfs.org/virt-builder.1.html




More information about the Libguestfs mailing list