Libvirt

From air
Jump to navigation Jump to search

Description

http://libvirt.org/

A toolkit to interact with the virtualization capabilities of recent versions of Linux (and other OSes)

Installation

Packages installation

apt-get install libvirt-bin


Creating an XML file configuration to import an existing container in libvirt

/!\ Notice that libvirt can not install am OS in a container. Therefore, an LXC container with an OS must have been set up previously (that was the we saw before). Then, the file system directory will be given to libvirt when importing the VM. /!\
In order to create a libvirt container, an XML file describing the VM we want to import must be filled. There is a sample of such an XML file that belong to VM "ubuntu1" we have just created :
<domain type='lxc'>
  <name>ubuntu1</name>
  <memory>332768</memory>
  <os>
    <type>exe</type>
    <init>/sbin/init</init>
  </os>
  <vcpu>1</vcpu>
  <clock offset='utc'/>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>destroy</on_crash>
  <devices>
    <emulator>/usr/lib/libvirt/libvirt_lxc</emulator>
    <filesystem type='mount'>
      <source dir='/var/lib/lxc/ubuntu1/rootfs'/>
      <target dir='/'/>
    </filesystem>
    <interface type='network'>
      <source network='default'/>
    </interface>
    <console type='pty' />
  </devices>
</domain>


Setting the container as a libvirt one

virsh --connect lxc:/// define ubuntu1.xml


Booting the container

virsh -c lxc:/// start ubuntu1


Connecting to the container localy

virsh -c lxc:/// console ubuntu1


Connecting to the container remotly

virsh -c lxc+{IPDEST}:/// console ubuntu1


Shutting the container

virsh -c lxc:/// destroy ubuntu1


Deleting the container

virsh -c lxc:/// undefine ubuntu1

Problemes

  • Using Ubuntu as a host,when connecting to a libvirt VM running Debian, the guest appliance waits for the user to log in through two interfaces at a time (tty1 and console), so it is not possible to get identified.
  • Using Debian Wheeze as a host, when connecting to a libvirt VM, the console does not offer the user the possibility to log in. However, when using directly LXC there is no issue.