

Create VM on KVM
Once you have KVM running, if you don’t have a test vm, you can install it using a virsh command like below:sudo virt-install \
--name centos7 \
--description "Test VM with CentOS 7" \
--ram=1024 \
--vcpus=2 \
--os-type=Linux \
--os-variant=rhel7 \
--disk path=/var/lib/libvirt/images/centos7.qcow2,bus=virtio,size=10 \
--graphics none \
--location $HOME/iso/CentOS-7-x86_64-Everything-1611.iso \
--network bridge:virbr0 \
--console pty,target_type=serial -x 'console=ttyS0,115200n8 serial'
This will install CentOS VM with:
- named centos7
- 2gb ram
- 2vcpu
- 10gb virtual disk
- default bridge attached – virbr0
Create VM snapshot on KVM
With your VM running, let’s proceed to create a snapshot. For a later demonstration on restoring VM state to snapshot, I’ll create two snapshots.$ sudo virsh snapshot-create-as --domain centos7 \ --name "centos7_vm_snapshot1" \ --description "centos7 vm snapshot 1" Domain snapshot centos7_vm_snapshot1 createdBefore we take a second snapshot, le’s install few packages:
$ sudo yum -y install vim elinks epel-releaseI’ll then take the second snapshot:
$ sudo virsh snapshot-create-as --domain centos7 \ --name "centos7_vm_snapshot2" \ --description "centos7 vm snapshot 2" Domain snapshot centos7_vm_snapshot2 createdWe’re now set to go.
List VM Snapshots on KVM
We have two snapshots taken initially, let’s check if we can see all these snapshots:$ sudo virsh snapshot-list test Name Creation Time State ------------------------------------------------------- centos7_vm_snapshot1 2018-03-24 22:09:48 +0300 shutoff centos7_vm_snapshot2 2018-03-24 02:09:28 +0300 running
Revert to VM Snapshot on KVM
To revert to a snapshot on KVM, use the commands shown below:$ sudo virsh snapshot-revert --domain centos7 --snapshotname \ centos7_vm_snapshot1 --runningThe VM should be restored to a state that we took the first snapshot.
Delete VM Snapshot on KVM
If you no longer need the VM snapshot, you can delete it using the command snapshot-delete followed by the name of the snapshot.$ sudo virsh snapshot-delete --domain centos7 --snapshotname centos7_vm_snapshot1 Domain snapshot centos7_vm_snapshot1 deletedIf you check a list of available snapshots now, you should see only one snapshot.
$ sudo virsh snapshot-list test
Display Snapshot details on KVM
Use the option snapshot-info with the virsh command to get more details about a given snapshot on KVM.sudo virsh snapshot-info --domain "$1" "$2"Where: Argument 1: domain name Argument 2: Snapshot name This guide has covered most basic snapshot management commands for KVM. Drop a comment if you have any issue and I’ll be happy to help. Also look at complete Virsh cheatsheet for more examples on how to use Virsh:
virsh commands cheatsheet to manage KVM guest virtual machines



































































