KVM snapshot

Дусал нэвтэрхий толь-с

How to create snapshot in Linux KVM VM/Domain

Before upgrading my virtual machine, I would like to make a snapshot. I want to revert a domain/VM to a snapshot if something goes wrong with my upgrade. Is there a command to create a snapshot of virtual machine (VM) while it is running? Does qemu-kvm support live snapshot creation?

Yes, KVM (Kernel Virtual Machine) does support both live and normal snapshots. The snapshot must base on qcow2 type disk. You can create a snapshot (disk and RAM) from arguments too. Snapshots are supported on KVM VM Host servers only. You can not create snapshots within KVM VM. You need to use any one of the following command:

   qemu-img command – QEMU disk image utility. Never use qemu-img to modify images in use by a running virtual machine or any other process. Machine must be in shutdown state to use qemu-img command.
   virsh command – The virsh program is the main interface for managing virsh guest domains including KVM. In this tutorial we are going to use the virsh command.


The virsh command can create a snapshot from XML file using virsh snapshot-create or directly from a set of options using virsh snapshot-create-as command. The syntax is: virsh snapshot-create-as --domain {VM-NAME} --name "{SNAPSHOT-NAME}"


   --domain {VM-NAME}: Domain name/VM name/id/uuid
   --name "{SNAPSHOT-NAME}": Name of snapshot


First list running VMS/guests/domain from host os:

  1. virsh list

Sample outputs:

Id    Name                           State

1     freebsd                        running
2     openbsd                        running
3     centos7                        running

To see existing snapshots (if any) for a domain called openbsd, enter:

  1. virsh snapshot-list --domain openbsd

Sample outputs:

Name                 Creation Time             State

3sep2016             2016-09-02 13:38:18 -0500 shutoff
3sep2016u1           2016-09-02 15:04:50 -0500 shutoff

Let us create a snapshot for freebsd domain. First, make sure freebsd domain using qcow2 disk:

  1. virsh dumpxml freebsd | grep -i qemu

Sample outputs:

     <driver name='qemu' type='qcow2'/>
     <driver name='qemu' type='raw'/>

To create a snapshot for a domain/VM called freebsd, enter:

  1. virsh snapshot-create-as --domain freebsd \

--name "5sep2016s0" \ --description "Snapshot before upgrading to FreeBSD 11" \ --live

Sample outputs:

Domain snapshot 5sep2016s0 created

You just took a snapshot from a running guest. This only captures the state of the disk and not the state of the memory. To take a new snapshot of a VM Guest called freebsd which currently not running:

  1. virsh shutdown freebsd
  2. virsh snapshot-create-as --domain freebsd \

--name "5Sep2016_S1" \ --description "My First Snapshpot"

  1. virsh start freebsd

To list snapshots for a domain called freebsd, enter:

  1. virsh snapshot-list --domain freebsd

OR for ubuntu-box2 vm: $ virsh snapshot-list --domain ubuntu-box2

Sample outputs: Fig.01: How to list snapshot with virsh KVM on Linux Fig.01: How to list snapshot with virsh KVM on Linux

To see detailed snapshot info for a domain called freebsd, enter:

  1. virsh snapshot-info --domain freebsd --snapshotname 5Sep2016_S1

Sample outputs: Fig.02: Creating and managing KVM snapshots with virsh Fig.02: Creating and managing KVM snapshots with virsh

How do I use/revert/restore a snapshot?

To revert a domain to a snapshot, enter:

  1. virsh shutdown --domain freebsd
  2. virsh snapshot-revert --domain freebsd --snapshotname 5Sep2016_S1 --running

Sample outputs: Fig.03: Revert domain to snapshot Fig.03: Revert domain to snapshot

How do I delete a domain snapshot?

Use the following syntax:

  1. virsh snapshot-delete --domain freebsd --snapshotname 5Sep2016_S2