Libvirt is a open source library which provides management of Virtual machine. It supports many function such as creation, deletion and update of VM. It is also used to run VM from XML configuration file. Libvirt is also used by well-known open source cloud platform openstack for the management of VM. It interacts with different hypervisors such as KVM, QEMU and XEN.
In libvirt terminology, a node / host is a single physical machine (hardware) and hypervisor / virtual machine monitor (VMM) is a software components which is used to virtualize a hardware resources into multiple VMs. A domain is an instance of an OS running on a VM provided by the hypervisor. Today announced new version libvirt-1.2.14 with around 350 commits and thanks to all contributors.
According to Libvirt documentation, it provides
a) Secure remote management using TLS.
b) Kerberos and SASL based authentication in remote management
c) Local access control using PolicyKit
d) Management of virtual resources such as VM, virtual networks and storage
In this article, we will use Libvirt on Ubuntu 14.04LTS. It can be installed using source code or binaries which are available in Ubuntu repository. Libvirt package is installed using following command in the terminal.
$sudo apt-get install libvirt-bin
After the successful installation of above package, provides commands such as virsh in the linux terminal. Virsh is used for following operation on VMs.
1) Dump of existing VM
2) Creation of new VM after modification in the XML file.
3) Volume and Network attachment with VM
4) Deletion of VM
5) Listing of Running VMs
Introduction : VM Management using Virsh
Virsh utility contains a comprehensive list of switches / parameters for VM management. All hypervisors stores VM their configuration in XML file. We can also take dump of running VM in XML file. In this article, we will use virt-install command line utility for the creation of VM in cli environment. Virt-install is a part of GUI tool “virt-manager” which is also used for VM creation. It can be installed using following command in Ubuntu
$sudo apt-get install virt-manager
After the installation of package, virt-install command is available for VM creation from CLI.
Few details of our new VM "test"are given below.
1) Qemu hypervisor
2) 512 RAM and 2GB volume space
3) Location of volume and debian net installer is at /var/lib/libvirt/images/
Following command will create new VM name “test” which is also shown in the Figure.
#virt-install --connect qemu:///system --virt-type qemu --name test --ram 512 --disk path=/var/lib/libvirt/images/test.img,size=2 --vnc --cdrom /var/lib/libvirt/images/debian-7.8.0-i386-netinst.iso --network network=default,mac=52:54:00:9c:94:3b
As shown in the above figure, test VM is in running State. Following command of virsh, lists all running VMs using any hypervisor.
#virsh list –all
Now we will take the dump of this test VM in XML file using following command .
#Virsh dumpxml test > test123.xml
test123.xml is the configuration dump of current running test VM. This XML configuration dump of VMused for the creation of new VM using virsh utility with slight modification in original file.
We have to change following XML tags in the dumped file for the creation of new VM.
1) Title of VM (Name of VM)
2) UUID of Volume (UUID is the unique id of VM storage/hard disk)
3) Mac address (unique MAC address for each VM)
4) Volume creation (creation of new volume for new VM)
We have launched new VM using virsh.
#virsh create /home/test/test123.xml
#virsh destroy test
In this tutorial, we learn the installation and usage of open source virtualization tool virsh on Ubuntu platform. Users can perform many other operation on the VM using virsh command such as network attachment /detachment, volume creation and attachment. It works with Qemu,KVM, XEN and many other commercial hypervisors such as VMware. In our next article on virsh tool, we will focus on new features such as creation of new network and attachment with running VM.