public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* disk image snapshot functionality
@ 2010-09-28 20:24 Peter Doherty
  2010-09-29  6:07 ` Takuya Yoshikawa
  2010-09-29  8:39 ` Stefan Hajnoczi
  0 siblings, 2 replies; 7+ messages in thread
From: Peter Doherty @ 2010-09-28 20:24 UTC (permalink / raw)
  To: kvm

Hi,

I'm using Centos5.5 on the host, and the KVM that's available in the  
repos.  I'm using linux VMs too.  My disk images are qcow2 files.
Here's what I want:
To be able to, on the host, create a snapshot of the guest's disk  
image, without shutting down the guest, so that I can then restore  
back to a point in time for the guest.
I thought I could do this with the qcow2 images.
I've used:
qemu-img snapshot -c snapname disk_image.qcow2
to create the snapshot.

It doesn't work.  The snapshots claim to be created, but if I shut  
down the guest, apply the snapshot
( qemu-img snapshot -a snapname disk_image.qcow2 )
the guest either:
a.) no longer boots (No bootable disk found)
b.) boots, but is just how it was when I shut it down (it hasn't  
reverted back to what it was like when the snapshot was made)


It makes no sense.  I can sometimes apply the first snapshot, and it  
has worked...but subsequent snapshots are a no go.
One thing that is suspicious is that the VM SIZE and CLOCK are zero:
# qemu-img snapshot -l test1.qcow2
Snapshot list:
ID        TAG                 VM SIZE                DATE       VM CLOCK
1         with100mb                 0 2010-09-28 11:48:23   00:00:00.000
2         with200mb                 0 2010-09-28 11:50:53   00:00:00.000
3         with300mb                 0 2010-09-28 11:52:49   00:00:00.000
4         whenoff                   0 2010-09-28 11:56:41   00:00:00.000


# /usr/libexec/qemu-kvm --help
QEMU PC emulator version 0.9.1 (kvm-83-maint-snapshot-20090205),  
Copyright (c) 2003-2008 Fabrice Bellard


I can't find much info about using qcow2 images when I search.  Any  
help would be appreciated.

Thanks.

Peter

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: disk image snapshot functionality
  2010-09-28 20:24 disk image snapshot functionality Peter Doherty
@ 2010-09-29  6:07 ` Takuya Yoshikawa
  2010-09-29  8:39 ` Stefan Hajnoczi
  1 sibling, 0 replies; 7+ messages in thread
From: Takuya Yoshikawa @ 2010-09-29  6:07 UTC (permalink / raw)
  To: Peter Doherty; +Cc: kvm

Hi,

(2010/09/29 5:24), Peter Doherty wrote:
> Hi,
>
> I'm using Centos5.5 on the host, and the KVM that's available in the repos. I'm using linux VMs too. My disk images are qcow2 files.
> Here's what I want:
> To be able to, on the host, create a snapshot of the guest's disk image, without shutting down the guest, so that I can then restore back to a point in time for the guest.

Yesterday, I heard a similar desire at the Virtualization End User Discussion @ LinuxCon Japan.

What you want to do is:
   - taking the whole VM disk image snapshot
     or
   - just taking specific partition's image?

Generally speaking, taking the whole VM disk image snapshot without breaking
guest side consistency seems difficult.

Even though you restrict to a specific partition, you need to guarantee that
the file system is in an appropriate state.


Anybody has better ideas?

   Takuya


> I thought I could do this with the qcow2 images.
> I've used:
> qemu-img snapshot -c snapname disk_image.qcow2
> to create the snapshot.
>
> It doesn't work. The snapshots claim to be created, but if I shut down the guest, apply the snapshot
> ( qemu-img snapshot -a snapname disk_image.qcow2 )
> the guest either:
> a.) no longer boots (No bootable disk found)
> b.) boots, but is just how it was when I shut it down (it hasn't reverted back to what it was like when the snapshot was made)
>
>
> It makes no sense. I can sometimes apply the first snapshot, and it has worked...but subsequent snapshots are a no go.
> One thing that is suspicious is that the VM SIZE and CLOCK are zero:
> # qemu-img snapshot -l test1.qcow2
> Snapshot list:
> ID TAG VM SIZE DATE VM CLOCK
> 1 with100mb 0 2010-09-28 11:48:23 00:00:00.000
> 2 with200mb 0 2010-09-28 11:50:53 00:00:00.000
> 3 with300mb 0 2010-09-28 11:52:49 00:00:00.000
> 4 whenoff 0 2010-09-28 11:56:41 00:00:00.000
>
>
> # /usr/libexec/qemu-kvm --help
> QEMU PC emulator version 0.9.1 (kvm-83-maint-snapshot-20090205), Copyright (c) 2003-2008 Fabrice Bellard
>
>
> I can't find much info about using qcow2 images when I search. Any help would be appreciated.
>
> Thanks.
>
> Peter
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: disk image snapshot functionality
  2010-09-28 20:24 disk image snapshot functionality Peter Doherty
  2010-09-29  6:07 ` Takuya Yoshikawa
@ 2010-09-29  8:39 ` Stefan Hajnoczi
  2010-09-29 14:35   ` Peter Doherty
  1 sibling, 1 reply; 7+ messages in thread
From: Stefan Hajnoczi @ 2010-09-29  8:39 UTC (permalink / raw)
  To: Peter Doherty; +Cc: kvm, Kevin Wolf

On Tue, Sep 28, 2010 at 9:24 PM, Peter Doherty
<doherty@hkl.hms.harvard.edu> wrote:
> I thought I could do this with the qcow2 images.
> I've used:
> qemu-img snapshot -c snapname disk_image.qcow2
> to create the snapshot.
>
> It doesn't work.  The snapshots claim to be created, but if I shut down the
> guest, apply the snapshot
> ( qemu-img snapshot -a snapname disk_image.qcow2 )
> the guest either:
> a.) no longer boots (No bootable disk found)
> b.) boots, but is just how it was when I shut it down (it hasn't reverted
> back to what it was like when the snapshot was made)

It is not possible to use qemu-img on the qcow2 image file of a
running guest.  It might work sometimes but chances are you'll corrupt
the image or end up with random behavior.  Compare this to mounting a
filesystem from the guest and the host at the same time - it is not
safe to do this!

You can take snapshots using the savevm command inside QEMU but that
will pause the guest.

If you use a logical volume instead of a qcow2 file then you can
create an LVM snapshot.  Try to ensure that the guest is in a
reasonably idle disk I/O state, otherwise the snapshot may catch the
guest at a bad time.  On boot up the filesystem may need to perform
some recovery (e.g. journal rollback).

Live disk snapshots could be supported at the QEMU block layer.  Once
a snapshot request is issued, all following I/O requests are queued
and not started yet.  Once existing requests have finished (the block
device is quiesced), the snapshot can be taken.  When the snapshot
completes, the queued requests are started and operation resumes as
normal.

Qcow2 is unique because it supports "internal" snapshots.  Disk
snapshots are part of the image file itself and blocks are shared
between snapshots using reference counting and copy-on-write.  Other
image formats only support "external" snapshots via backing files.
Examples of this are QCOW1, VMDK, and LVM (using LVM snapshot
commands).  In order to take an external snapshot you create a new
image file that uses the snapshot as a backing file.  New writes after
the snapshot go to the new file.  The old file is the snapshot and
should stay unmodified in the future.

Stefan

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: disk image snapshot functionality
  2010-09-29  8:39 ` Stefan Hajnoczi
@ 2010-09-29 14:35   ` Peter Doherty
  2010-09-30  8:31     ` Stefan Hajnoczi
  0 siblings, 1 reply; 7+ messages in thread
From: Peter Doherty @ 2010-09-29 14:35 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: kvm, Kevin Wolf

On Sep 29, 2010, at 04:39 , Stefan Hajnoczi wrote:

> On Tue, Sep 28, 2010 at 9:24 PM, Peter Doherty
> <doherty@hkl.hms.harvard.edu> wrote:
>> I thought I could do this with the qcow2 images.
>> I've used:
>> qemu-img snapshot -c snapname disk_image.qcow2
>> to create the snapshot.
>>
>> It doesn't work.  The snapshots claim to be created, but if I shut  
>> down the
>> guest, apply the snapshot
>> ( qemu-img snapshot -a snapname disk_image.qcow2 )
>> the guest either:
>> a.) no longer boots (No bootable disk found)
>> b.) boots, but is just how it was when I shut it down (it hasn't  
>> reverted
>> back to what it was like when the snapshot was made)
>
> It is not possible to use qemu-img on the qcow2 image file of a
> running guest.  It might work sometimes but chances are you'll corrupt
> the image or end up with random behavior.  Compare this to mounting a
> filesystem from the guest and the host at the same time - it is not
> safe to do this!
>
> You can take snapshots using the savevm command inside QEMU but that
> will pause the guest.
>
> If you use a logical volume instead of a qcow2 file then you can
> create an LVM snapshot.  Try to ensure that the guest is in a
> reasonably idle disk I/O state, otherwise the snapshot may catch the
> guest at a bad time.  On boot up the filesystem may need to perform
> some recovery (e.g. journal rollback).
>
> Live disk snapshots could be supported at the QEMU block layer.  Once
> a snapshot request is issued, all following I/O requests are queued
> and not started yet.  Once existing requests have finished (the block
> device is quiesced), the snapshot can be taken.  When the snapshot
> completes, the queued requests are started and operation resumes as
> normal.
>
> Qcow2 is unique because it supports "internal" snapshots.  Disk
> snapshots are part of the image file itself and blocks are shared
> between snapshots using reference counting and copy-on-write.  Other
> image formats only support "external" snapshots via backing files.
> Examples of this are QCOW1, VMDK, and LVM (using LVM snapshot
> commands).  In order to take an external snapshot you create a new
> image file that uses the snapshot as a backing file.  New writes after
> the snapshot go to the new file.  The old file is the snapshot and
> should stay unmodified in the future.
>
> Stefan


Thanks Stefan,

I suppose I could live with pausing the guest and then take the  
snapshot, and then resume.
Can you point me to any documentation about how to do this?  I'm  
really having a hard time finding any good docs on KVM with qcow2.
If I could pause the guest, create an internal qcow2 snapshot, and the  
resume the guest, that would work, if it means that I'd be able to  
restore the guest to how it was when the snapshot was taken.

I've considered LVM snapshots, but I hear that they suffer from a very  
large performance hit after two or more snapshots.
I guess I got some bad information about the features of qcow2 when I  
originally looked into using it.

-Peter

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: disk image snapshot functionality
  2010-09-29 14:35   ` Peter Doherty
@ 2010-09-30  8:31     ` Stefan Hajnoczi
  2010-09-30 13:49       ` Peter Doherty
  0 siblings, 1 reply; 7+ messages in thread
From: Stefan Hajnoczi @ 2010-09-30  8:31 UTC (permalink / raw)
  To: Peter Doherty; +Cc: kvm, Kevin Wolf

Try this:
http://wiki.qemu.org/download/qemu-doc.html#vm_005fsnapshots

To list the snapshots in your QCOW2 image:
qemu-img snapshot -l myimage.qcow2

To revert the disk to a saved state:
qemu-img snapshot -a <snapshot-name> myimage.qcow2

Stefan

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: disk image snapshot functionality
  2010-09-30  8:31     ` Stefan Hajnoczi
@ 2010-09-30 13:49       ` Peter Doherty
  2010-09-30 15:28         ` Stefan Hajnoczi
  0 siblings, 1 reply; 7+ messages in thread
From: Peter Doherty @ 2010-09-30 13:49 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: kvm, Kevin Wolf

On Sep 30, 2010, at 04:31 , Stefan Hajnoczi wrote:

> Try this:
> http://wiki.qemu.org/download/qemu-doc.html#vm_005fsnapshots
>
> To list the snapshots in your QCOW2 image:
> qemu-img snapshot -l myimage.qcow2
>
> To revert the disk to a saved state:
> qemu-img snapshot -a <snapshot-name> myimage.qcow2
>
> Stefan


Thanks,

It looks like the savevm and loadvm commands are pretty close to what  
I'm looking for.
Any idea what version of qemu that's available in, and when we might  
be seeing that version available in RHEL/CentOS?

Best,
Peter

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: disk image snapshot functionality
  2010-09-30 13:49       ` Peter Doherty
@ 2010-09-30 15:28         ` Stefan Hajnoczi
  0 siblings, 0 replies; 7+ messages in thread
From: Stefan Hajnoczi @ 2010-09-30 15:28 UTC (permalink / raw)
  To: Peter Doherty; +Cc: kvm, Kevin Wolf

On Thu, Sep 30, 2010 at 2:49 PM, Peter Doherty
<doherty@hkl.hms.harvard.edu> wrote:
> On Sep 30, 2010, at 04:31 , Stefan Hajnoczi wrote:
>
>> Try this:
>> http://wiki.qemu.org/download/qemu-doc.html#vm_005fsnapshots
>>
>> To list the snapshots in your QCOW2 image:
>> qemu-img snapshot -l myimage.qcow2
>>
>> To revert the disk to a saved state:
>> qemu-img snapshot -a <snapshot-name> myimage.qcow2
>>
>> Stefan
>
>
> Thanks,
>
> It looks like the savevm and loadvm commands are pretty close to what I'm
> looking for.
> Any idea what version of qemu that's available in, and when we might be
> seeing that version available in RHEL/CentOS?

The snapshot command was added in January 2009.  I don't have a RHEL 5
handy for checking, sorry.

Stefan

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2010-09-30 15:28 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-28 20:24 disk image snapshot functionality Peter Doherty
2010-09-29  6:07 ` Takuya Yoshikawa
2010-09-29  8:39 ` Stefan Hajnoczi
2010-09-29 14:35   ` Peter Doherty
2010-09-30  8:31     ` Stefan Hajnoczi
2010-09-30 13:49       ` Peter Doherty
2010-09-30 15:28         ` Stefan Hajnoczi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox