Re: qemu-img convert: Compression can not be disabled when converting from .qcow2 to .raw

2024-06-21 Thread Sven Ott

Thanks all, it works with qemu-img resize!


On 6/21/24 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







Re: qemu-img convert: Compression can not be disabled when converting from .qcow2 to .raw

2024-06-21 Thread Nir Soffer
On Fri, Jun 21, 2024 at 5:48 PM 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
>

This is not needed, and ineffective...


>
> qemu-img convert -f qcow2 -O raw $GUEST_IMG.img $GUEST_IMG.raw
>

Since the first thing done in this command is truncating the target image
to 0 bytes.

You can use -n to avoid creation of the target image and use your image,
but this is also not
needed.

You can convert the image:

qemu-img convert -f qccow2 -O raw src.qcow2 dst.raw

and then resize the raw image:

qmeu-img resize dst.raw newsize

You can also resize before converting, it does not matter if you resize
before or after.

Note that you will have to grow the pv/lv/filessystem inside the guest to
use the additional space.

Nir


Re: qemu-img convert: Compression can not be disabled when converting from .qcow2 to .raw

2024-06-21 Thread Jakob Bohm via

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




Re: qemu-img convert: Compression can not be disabled when converting from .qcow2 to .raw

2024-06-21 Thread Talha Khan
Maybe try first
qemu-img resize
then use qemu-img convert

On Fri, 21 Jun, 2024, 20:18 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
>
>
>
>


qemu-img convert: Compression can not be disabled when converting from .qcow2 to .raw

2024-06-21 Thread Sven Ott
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