Ошибка failed to connect to the hypervisor

Contents

  • Failed to connect to the hypervisor

    • No connection driver available

    • Cannot read CA certificate

    • Permission denied

    • Other errors

There are lots of errors that can occur while connecting to the server
(when running virsh for example)

No connection driver available¶

Symptom

When running a command, the following error (or similar) appears:

$ virsh -c <uri> list
error: no connection driver available for No connection for URI <uri>
error: failed to connect to the hypervisor

Cause

This can happen when libvirt is compiled from sources. The error means
there is no driver to use with the specified URI (e.g. «Xen» for
«xen://server/»)

Investigation

Check the last part of configure (‘./configure’ or ‘./autogen’) output,
you should see something like this:

configure: Drivers
configure:
configure: <driver>: yes

For example talking about Xen:

configure: Drivers
configure:
configure:     Xen: yes

If however you see «<driver>: no» (e.g. «Xen:no»), that means configure
failed to find all the tools/libraries necessary to implement this
support or there was «—without-<driver>» parameter specified on the
command line.

Solution

Do not specify «—without-<driver>» on the command line of the
configuration script and make sure there are all development libraries
installed as well, then configure the sources again.

Cannot read CA certificate¶

Symptom

When running a command, the following error (or similar) appears:

$ virsh -c <uri> list
error: Cannot read CA certificate '/etc/pki/CA/cacert.pem': No such file or directory
error: failed to connect to the hypervisor

Investigation

This error can be caused by various things, for some of them, the error
message is little misleading:

  1. specified URI is wrong (missing one ‘/’ — e.g. ‘qemu://system’)

  2. connection is not configured

Solution

specified URI is wrong

In the case of specifying ‘qemu://system’ or ‘qemu://session’ as a
connection URI, virsh is trying to connect to hostname ‘system’ or
‘session’ respectively because when hostname is specified, the transport
for qemu defaults to ‘tls’ and thus the need for a certificates. Use
three slashes in this case.

connection is not configured

You specified correct URI (e.g. ‘qemu[+tls]://server/system’) but the
certificates were not set up properly on your machine. There is a great
In depth guide to configuring TLS. The solution is
most probably there.

Permission denied¶

Symptom

When running a command, the following error (or similar) appears:

$ virsh -c qemu:///system list
error: Failed to connect socket to '/var/run/libvirt/libvirt-sock': Permission denied
error: failed to connect to the hypervisor

Investigation

You are trying to connect using unix socket. The connection to «qemu»
without any hostname specified is by default using unix sockets. If
there is no error running this command as root it’s probably just
misconfigured.

Solution

If you want to be able to connect as non-root user using unix sockets,
configure following options in ‘/etc/libvirt/libvirtd.conf’ accordingly:

unix_sock_group = <group>
unix_sock_ro_perms = <perms>
unix_sock_rw_perms = <perms>

Other errors¶

These other errors are even simpler to solve than those mentioned
before, so here is a list of error/solutions:

unable to connect to server at ‘server:port’: Connection refused

The daemon is not running on the server or it’s configured not to listen
(configuration option ‘listen_tcp’ or ‘listen_tls’).

End of file while reading data: nc: using stream socket: Input/output
error

If you specified ‘ssh’ transport, the daemon is probably not running on
the server.

End of file while reading data: : Input/output error

If you are using ssh transport, for example, by executing

virsh —connect qemu+ssh://username@remove.host.com/system list

Probably the user you are using to access the server does not belong to
the proper group, such as ‘libvirtd’ for Ubuntu servers. Try adding the
user to the proper group on server and connect again. For example, below
is to be run on Ubuntu servers.

sudo usermod -G libvirtd -a username

Refer to SSHSetup for setup about other
distributions.

I am trying to run kvm, but this error occurs:

$ virsh -c qemu:///system list
error: Failed to connect socket to '/var/run/libvirt/libvirt-sock': Permission denied
error: failed to connect to the hypervisor

So I enter to:

cd /var/run/libvirt/

and changed privilages by:

sudo chmod -R +777 libvirt

Everything is working now, but I have concerns about security issues, as privileges for all users and groups is not the safest way to do it? What could you recommend instead?

asked Oct 4, 2018 at 8:53

Linux In Practice's user avatar

Add your user to the kvm and libvirtd groups:

sudo usermod -aG kvm $USER
sudo usermod -aG libvirt $USER

After these group changes you have to logout/login the terminal you are using to have the changes taken into account. The groups you belongs to, can be check with the groups command.

Jeff Bauer's user avatar

Jeff Bauer

13.8k9 gold badges51 silver badges73 bronze badges

answered Oct 4, 2018 at 10:03

jeremf's user avatar

I think

sudo usermod -aG libvirt $USER

is the correct command

David Buck's user avatar

David Buck

3,72335 gold badges31 silver badges35 bronze badges

answered Jun 24, 2020 at 12:29

Syed Rizvi's user avatar

Same error i was getting

enter image description here

Solution this helps:-

#yum groupinstall «Virtualization Host»

#yum install qemu-kvm libvirt libvirt-python libguestfs-tools virt-install

#systemctl enable libvirtd.service

enter image description here

exit the use and re-login

Post above command executed, staring minkube i starting

enter image description here

answered Jul 6, 2022 at 18:58

Shiv's user avatar

ShivShiv

11410 bronze badges

Are you receiving the error failed to connect to the hypervisor while running virsh?

The reason for this can vary from no connection driver to missing permissions.

At Bobcares, we often get a request to fix virsh errors, as a part of our Server Management Services.

Today, let’s see why this error occurs and will also see how our Support Engineers fix it.

Virsh error failed to connect to the hypervisor

Virsh is a command-line tool used for managing guest VMs and the hypervisor. But connecting to the server while running virsh can sometimes end up in errors.

And one such error message is ‘error: failed to connect to the hypervisor’. There can be many possible reasons for this error to occur.

Let’s have a look at a few of them.

Causes and fixes for the virsh error

Our customers often approach us with errors while running virsh. Let’s see a few instances where our Support Engineers fixed this error.

1. Connection driver unavailable

While running a virsh command, a user got the following error message.

error: no connection driver available for No connection for URI 
error: failed to connect to the hypervisor

The error message clearly specifies that there is no connection driver for the URI. So our Support Engineers check the configure output. And it should appear as,

configure: Drivers
configure:
configure: : yes

We also check the development libraries and configure the sources if needed.

2. Unable to read CA certificate

Another customer got a different error message while running the virsh command. And the error message was,

error: Cannot read CA certificate '/etc/pki/CA/cacert.pem': No such file or directory
error: failed to connect to the hypervisor

This can be due to two possible reasons – incorrect URI or connection configuration error.

So our Support Engineers check the specified URI and correct it if needed. If the error is with the configuration, then it needs a detailed look. And our Experts check it and fix the error.

3. Permission denied error

Similarly, another error message while running a virsh command is,

error: Failed to connect socket to '/var/run/libvirt/libvirt-sock': Permission denied
error: failed to connect to the hypervisor

Here we check if the same error shows up while running the command as a root user. If the non-root user is only getting this error then the error is with the configuration.

To fix this our Support Engineers edit the /etc/libvirt/libvirt.conf file. And we add the permissions, which appears as,

#unix_sock_group = "libvirt"
#unix_sock_ro_perms = "0777"
#unix_sock_rw_perms = "0770"

Later we restart the libvirtd service. And this fixed the error.

4. Connection refused while running virsh

While trying to connect to a host system the virsh command fails with the error message.

error: failed to connect to the hypervisor
error: unable to connect to the server at 'host:16509': Connection refused

The error message indicates that the libvirt is not listening on the TCP port. So our Support Engineers check the /etc/libvirt/libvirtd.conf file.

And we ensure that the TCP port is listening. We also check if the libvirt configuration is correct or not.

For this, we open the /etc/sysconfig/libvirtd file. Here we uncomment the line,

virsh failed to connect to the hypervisor.

Later on, restarting the libvirt the error resolves.

5. Authentication failure while connecting to the hypervisor

In addition, some users get auth failed error while connecting to the server using virsh. Here the error message appears as

error: failed to connect to the hypervisor
error: authentication failed: authentication failed

This can be either due to incorrect credentials or else due to improper configuration.

So our Support Engineers check the /etc/libvirt/libvirtd.conf file. And ensure that the auth_tcp value is set to sasl. And we edit the /etc/sasl2/libvirt.conf file and add the following

mech_list: digest-md5
sasldb_path: /etc/libvirt/passwd.db

We also ensure to check the cyrus-sasl-md5 package. Later we restart the libvirt service and set user name and password for SASL.

[Need assistance in fixing virsh errors? – We can help you.]

Conclusion

So far we saw the various reasons for the virsh error failed to connect to the hypervisor. This can be due to driver connection, permissions, etc. Today, we saw how our Support Engineers fix this error.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = «owonCMyG5nEQ0aD71QM»;

@S4nfs, huge thanks for your appreciation of my work. I wish I could spend more time on my projects so that I could finish them and improve them from time to time 😅

Thanks a lot for providing me the full error message. In this case I think you’re right and it’s not something I could test on my side ’cause I’m only relying on the PHP embedded web server to run the web interface.

Regarding the deployment, I got two working deployments using the PHP embedded web server and then just using the script start-web-server.sh to fire it up. So, I got a local deployment and a remote deployment on a small dedicated server. That’s why I didn’t encountered similar issues as you did.

What I don’t understand in your case is why apparently libvirt is trying to write into your apache web folder under a .cache/libvirt subfolder…

Just to make sure that the issue is not in the code / to isolate it correctly, could you please just try running the script start-web-server.sh and see if you get the same issue?

Otherwise, if you can’t, what you can do would be to create that /var/www/.cache folder and set it temporarily to chmod 777 and see under which user the libvirt folder got created. Once done, try to restrict write access to only the related user used to create that libvirt folder.

Also, I don’t think that having deployed everything on the same host would be an issue. Basically if you check the code, I’m simply calling the libvirt binaries like virsh, parsing the output and render it in the web interface. And as I just deployed the code in the $HOME folder, I didn’t had the same permission issues you had.

I’ll try to setup a VM with apache + the nested virtualization enabled and do some tests to understand what caused your issue, debug it and then document my findings + workarounds if possible.

Thanks again for having took the time to report your issue 🙇🏽

19.06.2022

Всем доброго дня!
Изучаю сей чудный продукт, столкнулся с одной проблемкой. На свежеразвернутом по мануалам с wiki тестовом сервере пытаюсь запустить новую ВМ, но она сразу сваливается в статус «выключено». При этом, в журнале пишет, что не получается развернуть машину и подключиться к гипервизору:

[Z0][VM]: New state is ACTIVE
[Z0][VM]: New LCM state is BOOT_POWEROFF
[Z0][VMM]: Generating deployment file: /var/lib/one/vms/5/deployment.21
[Z0][VMM]: Successfully execute transfer manager driver operation: tm_context.
[Z0][VMM]: ExitCode: 0
[Z0][VMM]: Successfully execute network driver operation: pre.
[Z0][VMM]: Command execution fail: AVMBREST=0 SVMBREST=0 /var/lib/one/remotes/vmm/kvm/deploy ‘/var/lib/one/vms/5/deployment.21’ ‘br-test.ipa.local’ ‘0’ ‘0’ 5 br-test.ipa.local 9026a680c56a9d517a5d3048935f1a19339c89bf123b5cec2b37709ce436c8e3 0 0
[Z0][VMM][E]: Could not start domain one-5 error: failed to connect to the hypervisor
[Z0][VMM][E]: error: unable to connect to server at ‘br-test.ipa.local:16509’: Connection refused
[Z0][VMM]: ExitCode: 255
[Z0][VMM]: Failed to execute virtualization driver operation: deploy.
[Z0][VMM][E]: Error deploying virtual machine: one-5 0 0
[Z0][VM]: New state is POWEROFF
[Z0][VM]: New LCM state is LCM_INIT

Причем, эта ошибка возникает и в соло режиме и в режиме RAFT. В соло внешние диски не подключал, при этом хранилище system не показывает доступный объем (думал, что в этом причина). Но в RAFT с подключенными хранилищами по схеме LVM_LVM ситуация не меняется. Логические тома создаются, объем виден, но воз и ныне там.
Пробовал разные комбинации драйверов raw и qcow2 для iso и пустого образа.

Еще странное заметил — если в текущий момент узел виртуалки например третий, а лидер первый, то каталог /var/lib/one/vms/5 есть только на первом. В соло каталог все же присутствует, но от ошибки это не избавляет.

Я пока что тапок в этом вопросе, но что можно сделать, в какую сторону копать? По сути, все делал по мануалам, гугл не особо помогает.

24.06.2022

Сам затупил — сам нашел, где накосячил.
Пропустил спойлер в узлах виртуализации с установкой пакетов:
sudo apt install ipa-libvirt-qemu opennebula-node
sudo ipa-libvirt-qemu-configure

25.09.2022

Такая же ошибка на тестовом стенде после того как удалили хранилища из one и добавил эти же хранилища обратно.
До этого всё работало.
Ранее созданные VMs удалил. Так же удалил все образы.
Всё создал по новой. Но вот теперь машина не размещается ни на одном узле…

14.12.2022

Проверь сетевые настройки в бресте. Удали у виртуалок виртуальную сеть, у меня из за неправильных настроек сети не деплоилось. Проверь без сети.

14.12.2022

Мы проблему решили.
Проблема именно в не корректной работе OpenNebula старой с CEPH.
Косяки надо править командами в CEPH или просто с нуля создавать VMs (шаблоны).
В текущей версии OpenNebula это уже исправлено, а Бресте думаю не исправлено ещё.

Понравилась статья? Поделить с друзьями:
  • Ошибка failed to connect to the game в роблоксе
  • Ошибка failed to bind to port
  • Ошибка failed to authenticate your connection hypixel
  • Ошибка failed to associate with
  • Ошибка failed to allocate memory gates of hell