Dear Sven,
Note that qcow2 files contain data saying how large the virtual disk is
and what blocks in the virtual disk correspond to what blocks in the
qcow2 file.
Thus adding extra all-0 blocks at the end of a qcow2 file using generic
file manipulation tools like truncate or dd will not change the size or
content of the virtual disk image that can be extracted as a raw file.
Instead you need to resize the virtual disk inside the qcow2 file with
"qemu-img resize" subcommand before converting to a raw image.
Alternatively, you can use the generic file tools to change the size of
the raw file directly.
On 2024-06-21 16:46, Sven Ott wrote:
Hi, I want to mount a VM image to a loop device and give it some
excess space.
To do so, I download a .qcow2 file, add some 0 bytes with truncate,
and then convert the image from QCOW2 to RAW format with qemu-img
convert, like so:
```
GUEST_IMG=focal-server-cloudimg-amd64
wget https://cloud-images.ubuntu.com/focal/current/$GUEST_IMG
truncate -s 5G $GUEST_IMG.img
qemu-img convert -f qcow2 -O raw $GUEST_IMG.img $GUEST_IMG.raw
```
The problem is that the convert command throws away the 0-bytes which
have been appended earlier, leaving me with a .raw image of the
original size. As per the man page, the resulting image can be
optionally compressed with the -c flag, indicating that not providing
said flag would lead to an uncompressed resulting image.
I'm on Debian on x86_64; I've tried the qemu-img version 6.2 and 8.2
unsuccessfully so far.
Any help would be appreciated!
Sven
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