On Tue, Jun 23, 2020, 03:37 Jakob Bohm <jb-gnumli...@wisemo.com> wrote:

> Why not use qemu-img convert directly, it doesn't expose the disk
> content to any
> interface except the disk image file(s) created.
>

The context is uploading disks to a remote oVirt setup. You don't have
access to the target image.


> On 2020-06-23 00:21, Nir Soffer wrote:
> > I'm trying to export qcow2 images from ova format using qemu-nbd.
> >
> > I create 2 compressed qcow2 images, with different data:
> >
> > $ qemu-img info disk1.qcow2
> > image: disk1.qcow2
> > file format: qcow2
> > virtual size: 200 MiB (209715200 bytes)
> > disk size: 384 KiB
> > ...
> >
> > $ qemu-img info disk2.qcow2
> > image: disk2.qcow2
> > file format: qcow2
> > virtual size: 200 MiB (209715200 bytes)
> > disk size: 384 KiB
> > ...
> >
> > And packed them in a tar file. This is not a valid ova but good enough
> > for this test:
> >
> > $ tar tvf vm.ova
> > -rw-r--r-- nsoffer/nsoffer 454144 2020-06-22 21:34 disk1.qcow2
> > -rw-r--r-- nsoffer/nsoffer 454144 2020-06-22 21:34 disk2.qcow2
> >
> > To get info about the disks in ova file, we can use:
> >
> > $ python -c 'import tarfile; print(list({"name": m.name, "offset":
> > m.offset_data, "size": m.size} for m in tarfile.open("vm.ova")))'
> > [{'name': 'disk1.qcow2', 'offset': 512, 'size': 454144}, {'name':
> > 'disk2.qcow2', 'offset': 455168, 'size': 454144}]
> >
> > First I tried the obvious:
> >
> > $ qemu-nbd --persistent --socket=/tmp/nbd.sock --read-only --offset=512
> vm.ova
> >
> > And it works, but it exposes the qcow2 data. I want to raw data so I
> > can upload the guest
> > data to ovirt, where is may be converted to qcow2 format.
> >
> > $ qemu-img info --output json "nbd+unix://?socket=/tmp/nbd.sock"
> > {
> >      "virtual-size": 209715200,
> >      "filename": "nbd+unix://?socket=/tmp/nbd.sock",
> >      "format": "qcow2",
> >   ...
> > }
> >
> > Looking in qemu manual and qapi/block-core.json, I could construct this
> command:
> >
> > $ qemu-nbd --persistent --socket=/tmp/nbd.sock --read-only
> > 'json:{"driver": "qcow2", "file": {"driver": "raw", "offset": 512,
> > "size": 454144, "file": {"driver": "file", "filename": "vm.ova"}}}'
> >
> > And it works:
> >
> > $ qemu-img info --output json "nbd+unix://?socket=/tmp/nbd.sock"
> > {
> >      "virtual-size": 209715200,
> >      "filename": "nbd+unix://?socket=/tmp/nbd.sock",
> >      "format": "raw"
> > }
> >
> > $ qemu-img map --output json "nbd+unix://?socket=/tmp/nbd.sock"
> > [{ "start": 0, "length": 104857600, "depth": 0, "zero": false, "data":
> > true, "offset": 0},
> > { "start": 104857600, "length": 104857600, "depth": 0, "zero": true,
> > "data": false, "offset": 104857600}]
> >
> > $ qemu-img map --output json disk1.qcow2
> > [{ "start": 0, "length": 104857600, "depth": 0, "zero": false, "data":
> true},
> > { "start": 104857600, "length": 104857600, "depth": 0, "zero": true,
> > "data": false}]
> >
> > $ qemu-img convert -f raw -O raw nbd+unix://?socket=/tmp/nbd.sock
> disk1.raw
> >
> > $ qemu-img info disk1.raw
> > image: disk1.raw
> > file format: raw
> > virtual size: 200 MiB (209715200 bytes)
> > disk size: 100 MiB
> >
> > $ qemu-img compare disk1.raw disk1.qcow2
> > Images are identical.
> >
> > I wonder if this is the best way to stack a qcow2 driver on top of a
> > raw driver exposing
> > a range from a tar file.
> >
> > I found similar example for gluster in:
> > docs/system/device-url-syntax.rst.inc
> >
> > Richard suggested to try nbdkit tar plugin, but the plugin is not
> > available on RHEL,
> > and this adds additional dependency, when we already use qemu-nbd.
> >
> > Nir
> >
> >
>
>
> Enjoy
>
> Jakob
> --
> Jakob Bohm, CIO, Partner, WiseMo A/S.  https://www.wisemo.com
> Transformervej 29, 2860 Søborg, Denmark.  Direct +45 31 13 16 10
> This public discussion message is non-binding and may contain errors.
> WiseMo - Remote Service Management for PCs, Phones and Embedded
>
>
>

Reply via email to