For servers you need the following packages from the [[Official Repositories|official Arch Linux repositories]]:

For servers you need the following packages from the [[Official Repositories|official Arch Linux repositories]]:

* {{Pkg|libvirt}}

* {{Pkg|libvirt}}

−

* {{Pkg|urlgrabber}}

+

* {{Pkg|urlgrabber}} (required by {{Pkg|virtinst}})

−

* {{Pkg|qemu-kvm}}

+

* {{Pkg|qemu}} (optional if not using [[KVM]])

−

* {{Pkg|dnsmasq}}

+

* {{Pkg|dnsmasq}} (optional)

−

* {{Pkg|bridge-utils}}

+

* {{Pkg|bridge-utils}} (optional)

For GUI management tools, you also need all of the following from the official Arch Linux repositories:

For GUI management tools, you also need all of the following from the official Arch Linux repositories:

Line 28:

Line 25:

===Building libvirt for Xen===

===Building libvirt for Xen===

−

The [[PKGBUILD]] for both {{AUR|libvirt-git}} in the [[Arch User Repository|AUR]] and {{Pkg|libvirt}} in the [[Official Repositories|official repositories]] currently disables [[Xen]] support with the {{ic|--without-xen}} flag during the make process. If you want to use libvirt for managing Xen, you will need to [https://projects.archlinux.org/svntogit/community.git/tree/libvirt/repos/community-x86_64/ 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|libxenctrl}} installed.

+

The [[PKGBUILD]] for both {{AUR|libvirt-git}} in the [[Arch User Repository|AUR]] and {{Pkg|libvirt}} in the [[Official Repositories|official repositories]] currently disables [[Xen]] support with the {{ic|--without-xen}} flag during the make process. If you want to use libvirt for managing Xen, you will need to [https://projects.archlinux.org/svntogit/community.git/tree/libvirt/repos/community-x86_64/ 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|libxenctrl}} installed. If {{AUR|xen}} is installed, you don't need to install {{AUR|libxenctrl}}.

The alternative XenAPI driver is lacking a package at the moment? (2010-05-23, friesoft)

The alternative XenAPI driver is lacking a package at the moment? (2010-05-23, friesoft)

Line 35:

Line 32:

===Run daemon===

===Run daemon===

−

[[Daemon#Performing daemon actions manually|Start the libvirtd daemon]] and add {{ic|libvirtd}} to your [[Daemon#Starting on Boot|DAEMONS array]] so it starts automatically on boot.

−

−

It seems like you have to start {{ic|dbus}} and {{ic|avahi-daemon}} before starting {{ic|libvirtd}}.

−

{{Note|The Avahi daemon is used for local discovery of libvirt hosts via multicast-DNS. To disable this functionality, set {{ic|mdns_adv = 0}} in {{ic|/etc/libvirt/libvirtd.conf}}.}}

+

Change default user and group in {{ic|/etc/libvirt/qemu.conf}}. QEMU defaults to nobody:nobody.

−

===PolicyKit authentication===

+

[[Daemons#Starting_manually|Start the libvirtd daemon]] and enable the libvirt systemd service so it starts automatically on boot.

−

To allow a non-root user to manage virtual machines, you need to create the following file:

{{Note|The Avahi daemon is used for local discovery of libvirt hosts via multicast-DNS. To disable this functionality, set {{ic|1=mdns_adv = 0}} in {{ic|/etc/libvirt/libvirtd.conf}}.}}

−

Alternatively, you can grant only the monitoring rights with {{ic|org.libvirt.unix.monitor}}

+

===PolicyKit authorization===

+

To allow a non-root user to manage virtual machines, you need to create the following file (for polkit >= 0.107 only):

−

When logging in via [[Secure Shell|SSH]], you will need to make sure ConsoleKit is used. Place the following in {{ic|/etc/pam.d/sshd}}:

+

{{hc|/etc/polkit-1/rules.d/50-org.libvirt.unix.manage.rules|<nowiki>

+

polkit.addRule(function(action, subject) {

+

if (action.id == "org.libvirt.unix.manage" &&

+

subject.user == "<replace with user name>") {

+

return polkit.Result.YES;

+

}

+

});

+

</nowiki>}}

−

{{hc|/etc/pam.d/sshd|

+

Alternatively, you can grant only the monitoring rights with {{ic|org.libvirt.unix.monitor}}.

−

...

−

session optional pam_ck_connector.so

−

...

−

}}

For more information, see [http://wiki.libvirt.org/page/SSHPolicyKitSetup#Configuring_management_access_via_PolicyKit the libvirt wiki].

For more information, see [http://wiki.libvirt.org/page/SSHPolicyKitSetup#Configuring_management_access_via_PolicyKit the libvirt wiki].

Line 77:

Line 66:

$ newgrp libvirt

$ newgrp libvirt

−

Then you can either enable permissions-based access by uncommenting the following line in the [[PKGBUILD]] for libvirt before running {{ic|makepkg -s}}:

+

Uncomment the following lines in {{ic|/etc/libvirt/libvirtd.conf}} (they are not all in the same location in the file):

−

# 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 {{ic|/etc/libvirt/libvirtd.conf}} (they are not all in the same location in the file):

{{hc|/etc/libvirt/libvirtd.conf|<nowiki>

{{hc|/etc/libvirt/libvirtd.conf|<nowiki>

Line 96:

Line 82:

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:

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

+

egrep --color "vmx|svm" /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''.

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 {{ic|kvm-amd}} or {{ic|kvm-intel}} kernel module depending on your CPU.

−

# modprobe kvm-amd

−

−

Usually you would also add it to the {{ic|1=MODULES=}} line in {{ic|/etc/rc.conf}}

−

{{hc|/ect/rc.conf|<nowiki>

−

Modules=(... kvm-amd ...)

−

</nowiki>}}

If KVM is ''not'' working, you will find the following message in your {{ic|/var/log/libvirt/qemu/VIRTNAME.log}}:

If KVM is ''not'' working, you will find the following message in your {{ic|/var/log/libvirt/qemu/VIRTNAME.log}}:

Line 114:

Line 92:

More info is available from the [http://www.linux-kvm.org/page/FAQ official KVM FAQ]

More info is available from the [http://www.linux-kvm.org/page/FAQ official KVM FAQ]

+

+

===Stopping / resuming guest at host shutdown / startup ===

+

Running guests may be suspended (or shutdown) at host shutdown automatically using the libvirt-guests service. On the other hand, at host startup, this same daemon will resume (startup) the suspended (shutdown) guests automatically.

+

Check {{ic|/etc/conf.d/libvirtd-guests}} for libvirt-guests options.

==Usage==

==Usage==

Line 171:

Line 153:

To display the virtual machine desktop management tool:

To display the virtual machine desktop management tool:

$ virt-manager -c qemu+ssh://''username''@''host/IP address''/system

$ virt-manager -c qemu+ssh://''username''@''host/IP address''/system

+

+

{{Note|If you are having problems connecting to a remote RHEL server (or anything other than Arch, really), try the two workarounds mentioned in {{bug|30748}} and {{bug|22068}}.}}

===Using Python===

===Using Python===

Line 214:

Line 198:

</nowiki>}}

</nowiki>}}

−

{{Tip|It is recommended that you enable [[Wikipedia:Spanning_Tree_Protocol|Spanning Tree Protocol]] (STP) on the virtual bridge (e.g. ''br0'') that you create to avoid any potential bridging loops. You can automatically enable STP on the bridge at start-up by appending {{ic|brctl stp br0 on}} to {{ic|/etc/rc.local}}.}}

+

{{Tip|It is recommended that you enable [[Wikipedia:Spanning_Tree_Protocol|Spanning Tree Protocol]] (STP) on the virtual bridge (e.g. ''br0'') that you create to avoid any potential bridging loops. You can automatically enable STP by appending {{ic|1=POST_UP="brctl stp $INTERFACE on"}} to the netcfg profile.}}

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 libvirtgroup 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

Uncomment the following lines in /etc/libvirt/libvirtd.conf (they are not all in the same location in the file):

Note: You may also wish to change unix_sock_ro_perms from 0777 to 0770 to disallow read-only access to people who are not members of the libvirt group.

Enable KVM acceleration for QEMU

Note: KVM will conflict with VirtualBox. You cannot use KVM and VirtualBox at the same time.

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:

egrep --color "vmx|svm" /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.

If KVM is not working, you will find the following message in your /var/log/libvirt/qemu/VIRTNAME.log:

Stopping / resuming guest at host shutdown / startup

Running guests may be suspended (or shutdown) at host shutdown automatically using the libvirt-guests service. On the other hand, at host startup, this same daemon will resume (startup) the suspended (shutdown) guests automatically.
Check /etc/conf.d/libvirtd-guests for libvirt-guests options.

Usage

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).

Note: SELinux requires that virtual machines be stored in /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.

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 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

Note: VirtualBox support in libvirt is not quite stable yet and may cause your libvirtd to crash. Usually this is harmless and everything will be back once you restart the daemon.

virt-manager does not let you to add any VirtualBox connections from the GUI. However, you can launch it from the command line:

Tip: It is recommended that you enable Spanning Tree Protocol (STP) on the virtual bridge (e.g. br0) that you create to avoid any potential bridging loops. You can automatically enable STP by appending POST_UP="brctl stp $INTERFACE on" to the netcfg profile.

Guest configuration

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:

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' />: