Template:Article summary start Template:Article summary text Template:Article summary heading Template:Article summary wiki Template:Article summary wiki Template:Article summary wiki Template:Article summary wiki Template:Article summary wiki Template:Article summary end
- 1 Installing
- 2 Configuration
- 3 Usage
- 4 Remote access to libvirt
- 5 Bridged Networking
For servers you need the following packages from the official Arch Linux repositories:
- (required by )
- KVM) (optional if not using
For GUI management tools, you also need all of the following from the official Arch Linux repositories:
Building libvirt for Xen
The PKGBUILD for both AUR in the AUR and in the official repositories currently disables Xen support with the
--without-xen flag during the make process. If you want to use libvirt for managing Xen, you will need to grab the whole file set to enable Xen support and build your own libvirt package using the Arch Build System. Furthermore, you need to make sure you have AUR installed.
The alternative XenAPI driver is lacking a package at the moment? (2010-05-23, friesoft)
It seems like you have to start
avahi-daemon before starting
mdns_adv = 0in
To allow a non-root user to manage virtual machines, you need to create the following file:
[Allow a user to manage virtual machines] Identity=unix-user:<replace with your username> Action=org.libvirt.unix.manage ResultAny=yes ResultInactive=yes ResultActive=yes
Try to log in again if it does not work right away.
Alternatively, you can grant only the monitoring rights with
When logging in via SSH, you will need to make sure ConsoleKit is used. Place the following in
... session optional pam_ck_connector.so ...
For more information, see the libvirt wiki.
Unix file-based permissions
If you wish to use Unix file-based permissions to allow some non-root users to use libvirt, you can modify the configuration files.
First, you will need to create the
libvirt group and add any users you want to have access to libvirt to that group.
# groupadd libvirt # gpasswd -a [username] libvirt
Any users that are currently logged in will need to log out and log back in to update their groups. Alternatively, the user can use the following command in the shell they will be launching libvirt from to update the group:
$ newgrp libvirt
Then you can either enable permissions-based access by uncommenting the following line in the PKGBUILD for libvirt before running
# patch -Np1 -i "$srcdir"/unixperms.patch || return 1
Alternatively, you can make the changes to your permissions and configuration files by hand. Uncomment the following lines in
/etc/libvirt/libvirtd.conf (they are not all in the same location in the file):
#unix_sock_group = "libvirt" #unix_sock_ro_perms = "0777" #unix_sock_rw_perms = "0770" #auth_unix_ro = "none" #auth_unix_rw = "none"
0770to disallow read-only access to people who are not members of the
Enable KVM acceleration for QEMU
Running virtual machines with the usual QEMU emulation (i.e. without KVM)), will be painfully slow. You definitely want to enable KVM support if your CPU supports it. To find out, run the following command:
grep -E "(vmx|svm)" --color=always /proc/cpuinfo
If that command generates output, then your CPU supports hardware acceleration via KVM; if that command does not generate output, then you cannot use KVM.
To enable KVM, you need to load the
kvm-intel kernel module depending on your CPU.
# modprobe kvm-amd
Usually you would also add it to the
MODULES= line in
Modules=(... kvm-amd ...)
If KVM is not working, you will find the following message in your
Could not initialize KVM, will disable KVM support
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 standard
.iso file. Copy it to the
/var/lib/libvirt/images/ directory (alternatively, you can create a new storage pool directory in virt-manager and copy it there).
/var/lib/libvirt/images/by default. If you use SELinux and are having issues with virtual machines, ensure that your VMs are in that directory or ensure that you have added the correct labeling to the non-default directory that you used.
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 is not using all of its disk. However, this can cause increased fragmentation of the disk, and you must pay attention to the total available disk space on the VM host because it is much easier to over-allocate disk space to VMs.
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 are 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)
listen_tls = 0 listen_tcp = 1 auth_tcp=none
It is also necessary to start the server in listening mode by editing
The SSH.package is needed for remote management over
To connect to the remote system using
$ virsh -c qemu+ssh://username@host/IP address/system
If something goes wrong, you can get some logs using:
$ LIBVIRT_DEBUG=1 virsh -c qemu+ssh://username@host/IP address/system
To display the graphical console for a virtual machine:
$ virt-viewer --connect qemu+ssh://username@host/IP address/system myvirtualmachine
To display the virtual machine desktop management tool:
$ virt-manager -c qemu+ssh://username@host/IP address/system
General examples are given in
Unofficial example usingand :
#! /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 physical Ethernet from your virtual machines, you have to create a bridge between your physical Ethernet device (here eth0) and the virtual Ethernet device the VM is using.
libvirt creates the bridge virbr0 for NAT networking, so use another name such as br0 or virbr1. You have to create a new Netcfg Profile to configure the bridge, for example (with DHCP configuration):
INTERFACE="br0" CONNECTION="bridge" DESCRIPTION="KVM Bridge connection" BRIDGE_INTERFACES="eth0" IP="dhcp" ## sets forward delay time #FWD_DELAY=0 ## sets max age of hello message #MAX_AGE=10
brctl stp br0 onto
Now we have to activate the bridge interface in our VMs. If have a recent Linux machine, you can use this code in the .xml file:
[...] <interface type='bridge'> <source bridge='br0'/> <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='br0'/> <mac address='24:42:53:21:52:49'/> </interface> [...]