Context#
I am using KVM, and use/manage my VMs with virt-manager. But I asked myself this question: how can create or revert some snapshot?
I'm giving examples for qcow2 disk images and commands are made with virsh.
Internal Disk Snapshots#
You can list available VM with virsh in order to know their name:
1 | $ virsh list |
Then you can check if there already is existing shapshots for this VM:
1 | $ virsh snapshot-list vmname |
Next there is two possibilities to make a snapshot:
- create a XML snapshot description file to specify the name and description of the snapshot
- or let libvirt choose a name and no description
The XML snapshot description file must look like the following:
1 | <domainsnapshot> |
Make a snapshot with an XML file:
1 | $ virsh snapshot-create vmname /path/to/description.xml |
Or make a snapshot without description file:
1 | $ virsh snapshot-create vmname |
Note: this is much more faster to make a snapshot while the VM is stoped. But it's also possible to make a snapshot while the VM is running even if it's more slow.
If you want to see some information about the VM and snapshots you can run:
1 | $ qemu-img info /path/to/disk/image/vmname.qcow2 |
To revert the VM to a snapshot, for example run:
1 | $ virsh snapshot-revert vmname vmname-snapshot1 |