Following are the list of basic commands used to manage your vm through cli.

  1. List all the guest VM
#virsh list --all

2. List running guest VM

# virsh list

3. Enable auto starting of VM on reboot of host machine

#systemctl enable libvirtd
#systemctl start libvirtd
#virsh autostart VMName

4. Disable auto starting of VM

#virsh autostart VMName --disable

5. Starts an inactive guest.

#virsh start guestVM

6. Shut Down A Guest

#virsh shutdown guestVM

7. Rebooting A Guest

# virsh reboot guestVM

8. Suspend a guest virtual machine

# virsh suspend guestVM

9. Forcefully Stop A Guest

# virsh destroy guestVM

10. Find ip address of a running vm

a. Find the name of your vm
b. Find the mac address of your vm
c. Use arp command to get a KVM guest’s IP address

# virsh list# virsh dumpxml VM_NAME | grep “mac address” | awk -F\’ ‘{ print $2}’# arp -an | grep macaddress

11. Delete a VM

a. check and confirm the name of vm which you want to delete.

#virshs list --all

b. Note down a guest’s storage files. Here, my vm name is “openbsd”

#virsh dumpxml --domain openbsd | grep ‘source file’sample output: <source file=’/data/kvm/openbsd.qcow2'/>

c. Shutdown guestvm if it is running eg. vm name openbsd

#virsh shutdown openbsd

if above command fails , you can force a guest virtual machine to stop

#virsh destroy opensbd

d. delete a VM Guest

#virsh undefine openbsd

e. delete storage

#rm -rf /data/kvm/openbsd.qcow2

Since you can not delete vm with snapshot, so if step d fails

f. list snapshots

#virsh snapshot-list — domain openbsd

g. delete snapshot

# virsh snapshot-delete — domain VM_NAME — snapshotname SNAPSHOT_NAME

h. Repeat steps d & e

Note : Removing and deleting a virtual machine on Linux with all storage in single command

# virsh undefine --domain openbsd --remove-all-storage --delete-snapshots