2

I use qcow2 file format and create snapshots using a Virt-manager GUI. I assume I have 100GB disk space and 70% is used by VM at this moment. The qcow2-file size is about 70GB. I create a snapshot. It is stored inside the qcow2-file, we know. After some days the qcow2-file size is rised up to 120GB. OK, we understand, why. I delete this snapshot, but the qcow2-file size does not change!

"qemu-img info" does not show me any snapshots for this qcow2-file! How to see, what's inside this file and how to clean it up?

I've used "qemu-img convert" but I have a feeling inside that it's not the rigth way to decrease the file size.

Jaroslav Kucera
  • 1,435
  • 10
  • 16
Igor Schaefer
  • 41
  • 1
  • 5
  • Hi Igor, besides sparsifying the img, if you are wanting to see whats in your snapshot you may want to check out jollyroger's answer regarding mounting qcow2 snapshots, here: https://serverfault.com/questions/213232/mount-qcow2-snapshots – Gregory Martin Nov 14 '17 at 07:15

2 Answers2

3

In order to shrink the image, I'd suggest to use virt-sparsify

export TMPDIR=/var/tmp/
virt-sparsify --check-tmpdir=continue <name>.qcow2 <name>_sparsed.qcow2

Make sure you have enough space in the TMPDIR, otherwise the conversion would crash.

Don't use virt-sparsify on running VM images. You may end up with corrupted image! (see man)


Then you can also use compress option (-c) of the qemu-img convert. However that would probably have some impact on the performance, but probably only during startup and initial load of services.

Jaroslav Kucera
  • 1,435
  • 10
  • 16
2

qcow2 images can be inspected & mounted using quemu-nbd.

qemu-nbd --connect=/dev/nbd0 /path/to/your/vm-image.qcow2
fdisk /dev/nbd0 -l
mount /dev/nbd0p1 /mnt/your/mountpoint/

to list/create/delete snapshots use qemu-img snapshot

e.g. to list the available snapshots

qemu-img snapshot -l /path/to/your/vm-image.qcow2

to check snapshots content mount the snapshot

qemu-nbd --connect=/dev/nbd0 /path/to/your/vm-image.qcow2 --load-snapshot=1

the snapshot identifier is either its id or the name

hargut
  • 3,848
  • 6
  • 10