3

because of low space i would like to gunzip a zipped "glance image-download"
and compress it with qemu-img to a "qcow2" formatted file.

tried this:

gunzip -c file.gz |qemu-img convert -f raw /dev/stdin -O qcow2 file.qcow2 

but it fails with:

qemu-img: Could not open '/dev/stdin': Could not refresh total sector
count: Illegal seek

Any idea if this is at all possible?

2 Answers2

1

Build a workaround, like:
qemu-nbd --connect=/dev/nbd0 /my/disk/image.qcow2
gunzip -c rawImage.img.gz | dd of=/dev/nbd0

user447742
  • 11
  • 1
1

It's not possible to stream to/from stdin/stdout with qemu-img, but it is possible using nbdcopy + qemu-nbd:

$ qemu-img create -f qcow2 image.qcow2 1G
$ zcat file.gz | nbdcopy -- - [ qemu-nbd -f qcow2 image.qcow2 ]

The catch is unfortunately you have to know the size of the final qcow2 file before you start, although it's OK to use a larger size. I used 1G in the example above, which will fail if the uncompressed gzip file is larger than this.

Those dashes are all necessary. The double dash stops nbdcopy from processing the -f flag of qemu-nbd, and the single dash means "stream from stdin".

For completeness, here's how to stream qcow2 to stdout:

$ nbdcopy -- [ qemu-nbd -f qcow2 image.qcow2 ] - | file -
Rich
  • 303
  • 3
  • 6