How to shrink/decrease qcow2 size of VM in PVE 4.1?

fintnovo

Renowned Member
Jan 4, 2014
23
0
66
Good day, everyone. I have VM under PVE 4.1 with 100Gb virtual disk qcow2. Real data usage of guest machine - 10 Gb. I'd like to shrink/decrease size of virtual drive from 100Gb to 20Gb. With Resize Disk command I can only increase virtual drive size. Is any simple way to shrink/decrease virtual drive?
 
I did following:
stop virtual machine:
qm stop 100
convert the image from qcow2 to raw:
qemu-img convert vm-100-disk-1.qcow2 vm-100-disk-1.raw
then shrink the image the 20G are the new total size:
qemu-img resize -f raw vm-100-disk-1.raw 20G
then convert it back:
qemu-img convert vm-100-disk-1.raw vm-100-disk-1.qcow2
then erase the old .raw image
rm vm-100-disk-1.raw
then edit the "/etc/pve/qemu-server/100.conf" file and change
the the size of the disk to 20G

But when I try to start VM it didn't:
Image is not in qcow2 format.
 
Convert again from raw to qcow2 (with -O option):
qemu-img convert -O qcow2 vm-100-disk-1.raw vm-100-disk-1.qcow2
and VM start :) !
But, guest machine under Linux Ubuntu 14.04 didn't start normally:
111.png
something wrong with file system after converting?
 
Before using this command to shrink a disk image, you must use file system and partitioning tools inside the VM itself to reduce allocated file systems and partition sizes accordingly. Failure to do so will result in data loss.
After using this command to grow a disk image, you must use file system and partitioning tools inside the VM to actually begin using the new space on the device.

Any ideas how to solve?
 

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!