Convert¶
instar convert converts between disk image formats, as a drop-in
replacement for qemu-img convert.
# Convert QCOW2 to raw (flattens backing chains)
instar convert input.qcow2 output.raw
# Convert any input to QCOW2 v3 output
instar convert -O qcow2 input.raw output.qcow2
# Convert QCOW2 with backing chain to standalone QCOW2
instar convert -O qcow2 overlay.qcow2 standalone.qcow2
# Convert with compressed QCOW2 output (zlib/deflate compression)
instar convert -c -O qcow2 input.raw output.qcow2
# Convert with dense output (write all clusters including zeros)
instar convert --no-skip-zeros input.qcow2 output.raw
# Specify output cluster size for QCOW2 (512 to 2097152, default: 65536)
instar convert -O qcow2 --cluster-size 4096 input.raw output.qcow2
instar convert -O qcow2 --cluster-size 2097152 input.raw output.qcow2
# Write QCOW2 output with extended L2 entries (16-byte entries with subcluster bitmaps)
instar convert -O qcow2 --extended-l2 input.raw output.qcow2
# Write LUKS-encrypted QCOW2 output (AES-256-XTS, crypt_method=2)
instar convert -O qcow2 --luks-encrypt-passphrase 'secret' input.raw encrypted.qcow2
# Decrypt LUKS-encrypted QCOW2 back to raw
instar convert --luks-passphrase 'secret' encrypted.qcow2 output.raw
# Convert to VHD dynamic format
instar convert -O vpc input.qcow2 output.vhd
# Convert to VHDX dynamic format
instar convert -O vhdx input.qcow2 output.vhdx
# Convert to VHDX fixed format
instar convert -O vhdx --subformat fixed input.qcow2 output.vhdx
# Decrypt native LUKS v2 container (Argon2id KDF)
instar convert --luks-passphrase 'secret' --max-guest-memory 1G encrypted.luks output.raw
# Decrypt LUKS container wrapping a QCOW2 image
instar convert --luks-passphrase 'secret' luks-wrapped.img output.raw
# Specify VMDK grain size (4096 to 65536, default: 65536)
instar convert -O vmdk --grain-size 4096 input.raw output.vmdk
# Specify VHD block size (524288+, default: 2097152)
instar convert -O vpc --block-size 1048576 input.raw output.vhd
# Specify VHDX block size (a power of two from 1048576 to 268435456,
# default: qemu-img's for the size, 8388608 up to 1 GiB, 16777216 up to
# 100 GiB, 33554432 up to 32 TiB, then 67108864)
instar convert -O vhdx --block-size 4194304 input.raw output.vhdx
# Progress reporting
instar convert -p 5 input.qcow2 output.raw
The convert operation reads the virtual content of an input image (including
backing chain flattening) and writes it in the requested output format.
Compressed clusters (zlib/deflate and ZSTD) are decompressed transparently,
including clusters up to 2MB. QCOW2 v3 images with extended L2 entries
(subclusters) are also supported. Legacy AES-128-CBC encrypted QCOW2 images
(crypt_method=1) can be decrypted with --qcow2-password. LUKS-in-QCOW2
images (crypt_method=2) and native LUKS containers can be decrypted with
--luks-passphrase. LUKS v2 containers using Argon2id KDF require
--max-guest-memory (e.g., --max-guest-memory 1G). Native LUKS
containers wrapping QCOW2 images are transparently detected and
decrypted, with the inner QCOW2 processed as the conversion source.
That detection reads the first payload sector, and a read that fails
fails the conversion: an unreadable sector is not evidence that the
payload is flat, and converting it as though it were would write the
inner image's encrypted-then-decrypted bytes out under the target
format's name at exit 0.
Individual snapshots can be extracted with --snapshot <name-or-id>.
By default, convert produces sparse output by skipping zero-filled clusters
(matching qemu-img convert behavior). Use --no-skip-zeros for dense output.
The default can also be set via convert.sparse in the config file.
Supported output formats¶
- raw (default) - Flat raw output
- qcow2 - QCOW2 v3 output with 16-bit refcounts, configurable cluster
size (512 bytes to 64KB, default 64KB), optional zlib compression (
-c) - vmdk - VMDK monolithicSparse output (default), streamOptimized
with
-c, or monolithicFlat with--subformat monolithicFlat. Configurable grain size (4KB-64KB, default 64KB via--grain-size) for sparse/streamOptimized output. A monolithicFlat extent is named the wayqemu-imgnames it: the output's basename is split at its last.and the extent is<prefix>-flat<postfix>in the same directory, and the descriptor records that name.out.vmdkgivesout-flat.vmdk,out.imggivesout-flat.img,outgivesout-flat,a.b.cgivesa.b-flat.c, and.hidgives-flat.hid. An extent name that holds", CR or LF is refused before anything is written (see quirks.md). - vpc - VHD dynamic output, configurable block size (512KB+,
default 2MB via
--block-size) - vhdx - VHDX dynamic (default) or fixed (
--subformat fixed) output, configurable block size (any power of two from 1MB to 256MB via--block-size; by default qemu-img's for the size: 8MB up to 1GB, 16MB up to 100GB, 32MB up to 32TB, then 64MB). The virtual size is at most 64 TiB (70368744177664 bytes), the largest VHDX qemu-img creates: a larger source is refused before the output file is opened, withconvert: virtual size N exceeds the VHDX maximum of 64 TiB (70368744177664 bytes), and no output file is left behind. A size that is not a multiple of 512 is recorded rounded up to one, as qemu-img does. A fixed VHDX is written in place: every payload BAT entry isFULLY_PRESENTat its fixed offset, blocks that are all zero are left as holes, and the file is the fixed data start plus the virtual size long. If the filesystem cannot store a file that long, convert fails withconvert: a fixed VHDX of <N> bytes needs a <M>-byte file, which the filesystem holding '<f>' cannot store: <os error>.--subformatwith any other output format is refused with--subformat is only supported with VMDK (-O vmdk) or VHDX (-O vhdx) output, and a VHDX subformat other thandynamicorfixedwithunsupported VHDX subformat '<v>' (supported: 'dynamic', 'fixed'). This is the layout ofqemu-img create -o subformat=fixed,block_state_zero=off; see the "VHDX partial last block" section of quirks.md.
The size of the output¶
The output is as big as the source's virtual size. For a structured
source that is the size its header records. A raw or otherwise
unidentified source has no header to ask, so its virtual size is its
own file length rounded up to a 512-byte sector, which is what
qemu-img info reports for one and what instar info prints: a
1536-byte raw file converts to a 1536-byte raw image, and to a qcow2
whose virtual size is 1536. A file shorter than one sector rounds up,
so a 100-byte source converts to 512 bytes.
dd is the exception, because its count, skip and seek operands
describe a window of the source rather than the whole of it; see
dd.md.
Malformed block tables¶
convert refuses a VHD or VHDX block whose table entry names a byte
range that is the image's own structure, rather than reading the
image's metadata out as disk content. For VHD that is a BAT entry whose
block overlaps a region the image declares, which at an entry of zero
is the footer copy and the dynamic header:
convert: source block table names a block inside the image's own
structure, at host offset 0 (0x0); the format is recognised, the image
is malformed
Exit 1, and the output file is removed if nothing was written to it.
The wording matches what map and measure say about the same image,
so one image gets one answer whichever operation is asked, with the
host offset added because only the chain reader knows it. qemu reads
such a block out instead -- measured: qemu-img convert of a crafted
fixture yields the image's own cxsparse header as payload -- so
instar is deliberately stricter here. See docs/map.md for the walk
side and docs/format-internals.md for the predicate they share.
What a failed conversion leaves behind¶
convert creates its output file before launching the guest, so a
conversion the guest fails has already created the target. What is left
there depends on how far the run got:
| The run | The output file |
|---|---|
| wrote nothing | removed |
| wrote some of the image | kept, holding what was written |
was given the target with --no-create |
kept, whatever it holds |
An output holding bytes is kept because qemu-img convert keeps its
own, and those bytes are the only record of how far the run got. An
empty one is removed because qemu-img never leaves one -- it diagnoses
the failures that would produce it before creating the target at all --
and because a file that holds nothing still tells a caller testing for
the file's existence that the conversion ran.
Under --no-create the target is an image the user supplied to be
written into, which is never instar's to delete. The same applies to
the monolithicFlat extent file, which is removed on the same terms as
the descriptor.
The rule holds however the run failed: a refusal the guest reports, a
guest that crashes, or a request the host could not read (see "A
request the host cannot answer" in
guest-architecture.md). And only a regular
file is ever removed. A block device, /dev/null or a FIFO reports a
length of zero as well, but an output path naming one is a target the
user supplied, so a failed convert in.qcow2 /dev/sdb leaves the
device node where it was; an output path that is a symlink is left
alone too, along with whatever it points at.
instar copy follows the same rule.
Three cases produce an output that is sized up front rather than grown
as it is written, and such a file is never empty and so is always kept:
dd, convert -S 0 or --preallocation on a raw target, and
copy --preallocate-output.
Differencing images¶
A differencing VHD (footer disk type 4) or VHDX (HasParent set) stores
only the sectors that differ from a parent image. convert composes such
a source against its parent: it reads the parent's own backing chain
(following relative references beside the source, rejecting anything
outside the allowlist) and serves each sector from whichever image in the
chain actually owns it, so the output is byte-identical to the chain
flattened by hand.
If the source's own chain has no parent to read — a differencing image
with an empty or absent parent reference — convert still refuses it,
rather than composing from nothing:
convert: a differencing <VHD|VHDX> image in the chain convert was given
has no parent behind it, so the sectors it leaves to its parent could
not be composed
and exits 1 with no output file left behind. If the chain names a parent
that cannot be resolved — the file is missing, or outside the backing
file allowlist — discovery fails before any guest device is attached and
convert reports that instead, again leaving no output file.
See the "VHD/VHDX differencing" section of quirks.md for the per-operation record.