Tuesday, December 30, 2014

Managing KVM Virtual Machine using virsh

libvirt is a powerful tool kit for KVM and Xen virtual machine management. This blog does not intend to explain libvirt deeply but we provide some useful commands for KVM  daily operation.

Before using libvirt tool, you need to install in on your KVM hypervisor. OS is Ubuntu 14.04 in this example.

                  apt-get install libvirt-bin



 There are some commonly used options:

 create a virtual machine(e.g. server1) using a xml configuration file:

                   virsh define  server1.xml

find out what virtual machine created (you will use the names here for other operation):

                   virsh list --all 

boot up a virtual machine:

                   virsh start server1

shutdown a virtual machine:

                   virsh shutdown server1

Cold power down a virtual machine:

                   virsh destroy server1

remove a virtual machine:

                   virsh undefine server1

Instead of managing the virtual machine locally,you can also use virsh command to manage virtual remotely. Example:

                   virsh -c qemu+ssh://root@/system list --all 

This will show you all virtual machines created on remote KVM server. Notes: you may be prompted for root password if you have not been authorized on the remote KVM server using ssh-copy-id

                   ssh-copy-id root@ 


Comment is always welcome :)

                 

No comments:

Post a Comment