libvirt is an abstraction layer and a daemon for managing virtual machines -- remote or locally, using multiple virtualization backends (QEMU/KVM, VirtualBox, Xen, etc).
This entry doesn't try to cover everything about libvirt, just the things that were not intuitive at first or not well documented.
- 1 Installing
- 2 Configuration
- 3 Usage
- 4 Remote access to libvirt
- 5 Bridge Networking
For servers you need the following packages from the Arch repositories:
For GUI management tools you also need all of the following from Arch repositories: Template:Cli
Building libvirt for Xen
The PKGBUILD for Template:Codeline in the repositories currently disables xen with the "--with-out xen" flag during the make process. If you want to use libvirt for managing xen, you'll need grab the whole fileset to re-enable it. Furthermore you need to make sure you have libxenctrl installed.
The alternative XenAPI driver is lacking a package atm?? (23.5.2010, friesoft)
Seems that you have to start dbus and avahi-daemon before starting libvirtd.
To allow yourself to manage VMs as non-root, run this on the server:
Try to re-login if it doesn't work right away.
Alternatively you can only grant the monitoring rights with Template:Codeline
If logging in through ssh you will need to make sure ConsoleKit is used. Place the following in Template:Filename:
Unix File-based Permissions
If you wish to use unix file-based permissions to allow some non-root users to use Template:Codeline, you can modify the config files.
First you will need to create the libvirt group and add any users you want to have access to libvirt to that group.
Any users that are currently logged in will need to log out and back in to update their groups. Alternately the user can use the following command in the shell they will be launching libvirt from to update the group:
Then you can either enable permissions-based access by uncommenting the following line on the PKGBUILD for libvirt before running makepkg:
# patch -Np1 -i "$srcdir"/unixperms.patch || return 1
Alternatively, you can make the changes to your permissions and config files by hand. Uncomment the following lines in Template:Filename (they are not all in the same location in the file):
Enable KVM acceleration for QEMU
Running virtual machines with the usual QEMU emulation, without KVM, will be painfully slow. You definitely want to enable KVM support if your CPU supports it. To find out, run the following:
egrep '^flags.*(vmx|svm)' /proc/cpuinfo
More info is available from the official KVM FAQ
Installing a new VM
To create a new VM, you need some sort of installation media, which is usually a plain Template:Codeline file. Copy it to the "Template:Codeline" directory (alternatively you can create a new storage pool directory in virt-manager and copy it there)
Then run virt-manager, connect to the server, right click on the connection and choose New. Choose a name, and select Local install media. Just continue with the wizard.
On the 4th step, you may want to uncheck Allocate entire disk now -- this way you will save space when your VM isn't using all of its disk. However, this can cause increased fragmentation of the disk.
On the 5th step, open Advanced options and make sure that Virt Type is set to kvm. If the kvm choice is not available, see section Enable KVM acceleration for QEMU above.
Creating a storage pool in virt-manager
First, connect to an existing server. Once you're there, right click and choose Details. Go to Storage and press the + icon at the lower left. Then just follow the wizard. :)
Using VirtualBox with virt-manager
virt-manager does not let you to add any VirtualBox connections from the GUI. However, you can launch it from the command line:
virt-manager -c vbox:///system
Or if you want to manage a remote system over SSH:
virt-manager -c vbox+ssh://username@host/system
Remote access to libvirt
Using unencrypted TCP/IP socket (most simple, least secure)
If something goes wrong, you can get some logs using:
$ LIBVIRT_DEBUG=1 virsh -c qemu+ssh://username@host/system
To display the graphical console for a virtual machine: Template:Cli
To display the virtual machine desktop management tool: Template:Cli
General examples are given in Template:Filename
#! /usr/bin/env python2 # -*- coding: utf-8 -*- import socket import sys import libvirt if (__name__ == "__main__"): conn = libvirt.open("qemu+ssh://xxx/system") print "Trying to find node on xxx" domains = conn.listDomainsID() for domainID in domains: domConnect = conn.lookupByID(domainID) if domConnect.name() == 'xxx-node': print "Found shared node on xxx with ID " + str(domainID) domServ = domConnect break
To use phisical ethernet from your virtual machines you have to create a bridge with your phisical ethernet (here eth0).
Llibvirt creates the bridge virbr0 for NAT networking so use another name such as virbr1. You have to create a new Network Profile to configure the bridge, for example (with DHCP configuration):
Now we have to activate the bridge interface in our VMs. If have a recent Linux machine we can use this code in the .xml file:
[...] <interface type='bridge'> <source bridge='virbr1'/> <mac address='24:42:53:21:52:49'/> <model type='virtio' /> </interface> [...]
This code activates a virtio device on the machine so, in Windows you will have to install an additional driver (you can find it here Windows KVM VirtIO drivers) or remove the line <model type='virtio' />:
[...] <interface type='bridge'> <source bridge='virbr1'/> <mac address='24:42:53:21:52:49'/> </interface> [...]