Howto Change virtual size of a qcow2 Image

mike2012

Renowned Member
Apr 29, 2015
42
1
73
I have a qcow2 Image with virtual size 600GB.
Inside i have Windowspartition with 150GB.
Now i have to change the virtual size to something near 150GB.

qemu-img --info also reports this values and the 450GB never been used for something else

is there a simple way to do so. (NO converting to raw, NO file copy.)

qm resize 100 virtio0 160G ... not working.
qemu-img resize ..... 160G ... not working.
 
That doesnt help me realy.
Everyone talks about enlarging a virtual disk.
Thats not my Problem.
I want to shrink the VIRTUAL size of the qcow2 image to the real size of the content.
 
well of course most people wish to grow disks usually.
but also you said
"I have a qcow2 Image with virtual size 600GB.
Inside i have Windowspartition with 150GB.
Now i have to change the virtual size to something near 150GB."

so, the qcow2 file could be much less of the virtual size, so it could not waste your space. It could be physically near to 150GB.
try examininig df and du command output about that file to check.

Anyway I found also this
https://pve.proxmox.com/wiki/Shrink_Qcow2_Disk_Files

but I guess your desire for "(NO converting to raw, NO file copy.)" can't be fullfilled...

Sorry, this is what I know.
Marco
 
Thx for your replay, but your link is the same as always .. telling me how to reduce the REAL size of a qcow2 file.
I was thinking there must be a simple way to tell the qcow2 file a new max size ( virtual size ).

If there is not, i have to go the long way with making a Image of the content and then recover this image to a smaler qcow2 image.
 
Thx for your answer, but that works only on raw images, doing that on a qcow2 image ends with :

qemu-img: qcow2 doesn't support shrinking images yet
qemu-img: This image does not support resize

So the only official way seems to be, converting the qcow2 image into a useless huge raw image , shrink that and convert it back to qcow2.
 
So the only official way seems to be, converting the qcow2 image into a useless huge raw image , shrink that and convert it back to qcow2.

well you could use pve "live storage migration" to convert the qcow2 to raw with no downtime, then stop the vm, shrink that raw file, restart the vm using that raw file and then again use pve "live storage migration" to convert the raw to qcow2 with no downtime...

Marco
 
Thx but not realy a good solution because i need the space for the qcow2 and the raw Image at the same time for only changing the virtual size.
But if i find no other solution i will go this way.
 
Hi all,

My Host system is Linux; I resized my Windows Guest by increasing its size from 40 GB to 80 GB successfully (first qemu-img resize and then with gparted); now also the Guest OS is able to see it has 80GB instead of 40 GB at its disposal (and can install all the updates it likes). However, how can that be that the qcow2 image file is still 40 GB, and not 80GB? Is the qcow2 file as big as the file system of its guest, or is it compressed? I can't explain it... Thanks!
 
I have solved it creating a new virtual disk with the final size you want.

Then you can clone the original qcow2 disk with gparted. Make sure you copy the MBR with:

dd if=/dev/sda of=/dev/sdb bs=446 count=1

or

dd if=/dev/sda of=/mnt/mbr.bin bs=446 count=1
dd if=/mnt/mbr.bin of=/dev/sdb bs=446 count=1

otherwise converting to raw creates a disk file with full size, sometimes you don´t have room in your HD for that.

Then you can replace your original qcow2 disk with the cloned one.
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!