Thursday, February 19, 2015

How to manage KVM virtual machines using virsh

virsh is a program which uses libvirt to manage KVM virtual machines (guests).

I’m going to show a summary of its main functions 

Show Hosts’ information:
  • Show a host’s info: virsh nodeinfo
  • Show KVM version installed: virsh version
Show guests’ information:
  • Show a list of all the defined guests: virsh list –all
  • Show a list of all running gust: virsh list
  • Show a guest’s info: virsh dominfo guest's_name 
  • To display virtual CPU information: virsh vcpuinfo guest's_name
Start and stop guests:
  • Start a guest: virsh start guest's_name
  • Shutdown a guest (gently): virsh shutdown guest's_name
  • Shutdown a guest (wild): virsh destroy guest's_name
  • Reboot a guest: virsh reboot guest's_name
  • Suspend a guest: virsh suspend guest's_name
  • Resume a suspended guest: virsh resume guest's_name
Create and modify guests:
  • Create a guest from its XML definition: virsh create xml_file.xml
  • Dump a guest’s definition in XML: virsh dumpxml guest's_name
  • Modify a guest’s definition: virsh edit guest's_name 
this uses the default editor. To use another editor like nano, you can use
EDITOR=nano virsh edit guest's_name

  • Remove a guest’s definition (it doesn’t remove the image file): virsh undefine guest's_name
Backup and restore guests:
  • Save a guest’s state on a file: virsh save guest's_name guest's_state_file
  • Restore a guest from a state file: virsh restore guest's_state_file

No comments:

Post a Comment