Linux – mount qcow2 snapshots

kvm-virtualizationlinuxqcow2

I'm running some Xen-servers and started migrating to KVM.

Currently my guests are either running on raw-images or LVMs.

I found libvirt providing some very nice snapshot features (virsh snapshot-create, …) so I decided to use qcow2 instead of raw/lvm.

And here is my question: libvirt creates the same sort of snapshots on the qcow2 image as if I use qemu-img – is it possible to mount them ? I read something about qemu-nbd and the possibility of mounting qcow but I could not find a word about snapshots.

Best Answer

You should apply the snapshot and mount the image like always. It's better to create a snapshot right before applying if you want to turn back to the original disk contents before you do these operations. After you apply the snapshot you just mount the image with qemu-nbd as always:

# modprobe nbd max_part=8
$ qemu-img snapshot -c backup image.qcow2
$ qemu-img snapshot -a old_snapshot image.qcow2
$ qemu-nbd --connect=/dev/nbd0 image.qcow2
# mount /dev/nbd0p1 /mnt

You might want to save snapshot separately and mount it as another disk drive. For this you should use convert comand for qemu-img.

$ qemu-img convert -s old_snapshot image.qcow2 old_snapshot.qcow2
$ qemu-nbd --connect=/dev/nbd0 old_snapshot.qcow2
# mount /dev/nbd0p1 /mnt    

See man qemu-img(1) and qemu-nbd(1) for more details.