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:

  1. 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.
  2. 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.

Syntax to create snapshot in Linux for KVM VM

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 as follow to make snapshot in Linux for KVM vm:
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:
# 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:
# 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:
# 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:
# virsh snapshot-create-as --domain freebsd \
--name "5sep2016s0" \
--description "Snapshot before upgrading to FreeBSD 11" \

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:
# virsh shutdown freebsd
# virsh snapshot-create-as --domain freebsd \
--name "5Sep2016_S1" \
--description "My First Snapshpot"
# virsh start freebsd

To list snapshots for a domain called freebsd, enter:
# 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:
# 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:
# virsh shutdown --domain freebsd
# 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:
# virsh snapshot-delete --domain freebsd --snapshotname 5Sep2016_S2

How to capture disk state but not vm state

Pass the --disk-only as follows:
# virsh snapshot-create-as --name "snap01" \
--description "RHEL 7.6 snapshot" \
--disk-only \
--domain rhel7-vm2

How to get help about snapshot-create-as commands

virsh help snapshot-create-as
Sample outputs:

    [--domain] <string>  domain name, id or uuid
    --name <string>  name of snapshot
    --description <string>  description of snapshot
    --print-xml      print XML document rather than create
    --no-metadata    take snapshot but create no metadata
    --halt           halt domain after snapshot is created
    --disk-only      capture disk state but not vm state
    --reuse-external  reuse any existing external files
    --quiesce        quiesce guest's file systems
    --atomic         require atomic operation
    --live           take a live snapshot
    --memspec <string>  memory attributes: [file=]name[,snapshot=type]
    [--diskspec] <string>  disk attributes: disk[,snapshot=type][,driver=type][,file=name]


This page showed how to create a snapshot (disk and RAM) from arguments for KVM VM using the virsh cli. See virsh command reference here for more info.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 3 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersncdu pydf
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
3 comments… add one
  • David Pham Dec 9, 2016 @ 20:49

    Great notes – Thanks

  • Trang Jul 28, 2017 @ 12:14


    I got follow error when creating a snapshot, any ideas for this?

    # virsh snapshot-create-as test –name “test_snapshot_July28” –live
    error: this function is not supported by the connection driver: virDomainSnapshotCreateXML


  • Shekhar Londhe Sep 4, 2017 @ 8:59

    Hi Vivek,
    Thank you for posting this article. It is very helpful. I would like to suggest a quick correction regarding the state of VM when we are creating the snapshot.
    You have mentioned that the state of the VM is not saved if we are creating the snapshot using command:

    virsh snapshot-create-as --domain freebsd \
    --name "5sep2016s0" \
    --description "Snapshot before upgrading to FreeBSD 11" \

    After going through the manual for virsh command I could find out that ‘virsh snapshot-create-as’ by default stores the VM state in a snapshot.
    If we don’t want this state then we need to specify the parameter “--disk-only” to avoid the VM state to be captured in snapshot.
    Thanks again.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum