Connection URIs

Since libvirt supports many different kinds of virtualization (often referred to as "drivers" or "hypervisors"), we need a way to be able to specify which driver a connection refers to. Additionally we may want to refer to a driver on a remote machine over the network.

To this end, libvirt uses URIs as used on the Web and as defined in RFC 2396. This page documents libvirt URIs.

Specifying URIs to libvirt

The URI is passed as the name parameter to virConnectOpen or virConnectOpenReadOnly. For example:

virConnectPtr conn = virConnectOpenReadOnly ("test:///default");

Configuring URI aliases

To simplify life for administrators, it is possible to setup URI aliases in a libvirt client configuration file. The configuration file is /etc/libvirt/libvirt.conf for the root user, or $XDG_CONFIG_HOME/libvirt/libvirt.conf for any unprivileged user. In this file, the following syntax can be used to setup aliases

uri_aliases = [
  "hail=qemu+ssh://root@hail.cloud.example.com/system",
  "sleet=qemu+ssh://root@sleet.cloud.example.com/system",
]

A URI alias should be a string made up from the characters a-Z, 0-9, _, -. Following the = can be any libvirt URI string, including arbitrary URI parameters. URI aliases will apply to any application opening a libvirt connection, unless it has explicitly passed the VIR_CONNECT_NO_ALIASES parameter to virConnectOpenAuth. If the passed in URI contains characters outside the allowed alias character set, no alias lookup will be attempted.

Default URI choice

If the URI passed to virConnectOpen* is NULL, then libvirt will use the following logic to determine what URI to use.

  1. The environment variable LIBVIRT_DEFAULT_URI
  2. The client configuration file uri_default parameter
  3. Probe each hypervisor in turn until one that works is found

Specifying URIs to virsh, virt-manager and virt-install

In virsh use the -c or --connect option:

virsh -c test:///default list

If virsh finds the environment variable VIRSH_DEFAULT_CONNECT_URI set, it will try this URI by default. Use of this environment variable is, however, deprecated now that libvirt supports LIBVIRT_DEFAULT_URI itself.

When using the interactive virsh shell, you can also use the connect URI command to reconnect to another hypervisor.

In virt-manager use the -c or --connect=URI option:

virt-manager -c test:///default

In virt-install use the --connect=URI option:

virt-install --connect=test:///default [other options]

xen:///system URI

This section describes a feature which is new in libvirt > 0.2.3. For libvirt ≤ 0.2.3 use "xen".

To access a Xen hypervisor running on the local machine use the URI xen:///system.

qemu:///... QEMU and KVM URIs

To use QEMU support in libvirt you must be running the libvirtd daemon (named libvirt_qemud in releases prior to 0.3.0). The purpose of this daemon is to manage qemu instances.

The libvirtd daemon should be started by the init scripts when the machine boots. It should appear as a process libvirtd --daemon running as root in the background and will handle qemu instances on behalf of all users of the machine (among other things).

So to connect to the daemon, one of two different URIs is used:

(If you do libvirtd --help, the daemon will print out the paths of the Unix domain socket(s) that it listens on in the various different modes).

KVM URIs are identical. You select between qemu, qemu accelerated and KVM guests in the guest XML as described here.

Remote URIs

Remote URIs are formed by taking ordinary local URIs and adding a hostname and/or transport name. As a special case, using a URI scheme of 'remote', will tell the remote libvirtd server to probe for the optimal hypervisor driver. This is equivalent to passing a NULL URI for a local connection. For example:

Local URI Remote URI Meaning
xen:///system xen://oirase/system Connect to the Xen hypervisor running on host oirase using TLS.
NULL remote://oirase/ Connect to the "default" hypervisor running on host oirase using TLS.
xen:///system xen+ssh://oirase/system Connect to the Xen hypervisor running on host oirase by going over an ssh connection.
test:///default test+tcp://oirase/default Connect to the test driver on host oirase using an unsecured TCP connection.

Remote URIs in libvirt offer a rich syntax and many features. We refer you to the libvirt remote URI reference and full documentation for libvirt remote support.

test:///... Test URIs

The test driver is a dummy hypervisor for test purposes. The URIs supported are:

Other & legacy URI formats

NULL and empty string URIs

Libvirt allows you to pass a NULL pointer to virConnectOpen*. Empty string ("") acts in the same way. Traditionally this has meant connect to the local Xen hypervisor. However in future this may change to mean connect to the best available hypervisor.

The theory is that if, for example, Xen is unavailable but the machine is running an OpenVZ kernel, then we should not try to connect to the Xen hypervisor since that is obviously the wrong thing to do.

In any case applications linked to libvirt can continue to pass NULL as a default choice, but should always allow the user to override the URI, either by constructing one or by allowing the user to type a URI in directly (if that is appropriate). If your application wishes to connect specifically to a Xen hypervisor, then for future proofing it should choose a full xen:///system URI.

Legacy: "xen"

Another legacy URI is to specify name as the string "xen". This will continue to refer to the Xen hypervisor. However you should prefer a full xen:///system URI in all future code.