QEMU/KVM: Changing the default connect URI in libvirt

All the libvirt related commands, like virsh, virt-viewer or virt-install take a connect URI as parameter. The connect URI can be thought as specifying which set of virtual machines you want to control with that command, which physical machine to control, and how.

For example:

1
virsh --connect "qemu+ssh://super@servers.arcade.click" start node011

If you don’t specify any connect URI to virsh (or any other libvirt related command), by default libvirt will try to start a VM running as your username on your local machine (eg, qemu:///session). This unless you are running as root, in which case libvirt will try to run the image as a system image, not tied to any specific user (eg, qemu:///system).

Usually we run most VMs as system VMs, and systematically forget to specify which connect URI to use to commands like virsh or virt-install. What is more annoying is that some of those commands take the URI as -c while others as -C.

However, turns out that most of those commands rely on libvirt, and that libvirt itself looks at LIBVIRT_DEFAULT_URI to pick the default connect URI.
Just need to add a variable with URI (qemu:///system) into workning .bahsrc:

1
export LIBVIRT_DEFAULT_URI="qemu:///system"
Scroll to top