Ask Your Question

Resize image: Smallest?

asked 2015-04-24 20:57:12 -0500

datts gravatar image

updated 2015-04-25 03:08:55 -0500

Hi everyone,

I have a file image qcow2(Ubuntu cloud-image ~ 244M, download from And now, i want convert this file image to raw type, so that file image size the smallest possible.


Usually, i use --disk-format qcow2 to upload glance. Now, I convert file image from qcow2 to raw, example:

qemu-img convert -f qcow2 ubuntu-qcow2.img -O raw ubuntu_raw.img

Size of file image:

Before convert: ubuntu-qcow2.img: 244MB

After: ubuntu-raw.img: 2.2GB

We can create instances from both ubuntu-qcow2.img and ubuntu_raw.img

Here, I want resize (down) file ubuntu-raw.img < 2.2GB the smallest possible, without making error image.

You have a new idea for this problem? Thank you :)

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2015-04-24 23:20:27 -0500

SamYaple gravatar image

updated 2015-04-24 23:21:11 -0500

What you are asking for is a sparse file. Unfortunately, that is not "raw". raw is going to be the full, uncompressed size of the image it is representing. You can create the image with a "raw" format and still keep it a sparse file, but once you upload/download that it will take full amount of space. The reason being is that a sparse file relies on metadata to know which bits have data and which bits can be generated. This metadata is stored in the filesystem.

qcow2 is a sparse file format that consists of only used blocks, but it has metadata to track these used blocks in the file itself. That means it can be transferred without around in a small size without relying on compression or filesystem tricks.

Now, in an officially unsupported capacity, you can probably tweak that backing image once its been uploaded through the API to use those filesystem tweaks to recreate that sparse file. This likely won't be what you want though since you'd need a shared storage backed to take advantage of that, and if you had that you likely wouldn't care about a gig or two.

In the case of a backend like ceph, you can probably use TRIM to get back that "lost" space, but that can also be tricky.

Can you update your question with what you are trying to do in more detail that just 'the smallest possible size'? Perhaps we can suggest an alternative.

edit flag offensive delete link more


Hi SamYaple,

I've updated my question.

Thank you.

datts gravatar imagedatts ( 2015-04-25 03:07:50 -0500 )edit

The answer would still be the same. The only way you can make a raw file smaller is to mount the raw image as a filesystem and manually resize it. The raw file is an accurate representation of the guest image and the only way to make it smaller is to make the filesystem in the image smaller.

jdexter gravatar imagejdexter ( 2015-04-25 08:30:02 -0500 )edit

Thanks jdexter and SamYaple :)

datts gravatar imagedatts ( 2015-04-25 08:43:24 -0500 )edit

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower


Asked: 2015-04-24 20:57:12 -0500

Seen: 1,634 times

Last updated: Apr 25 '15