'error: Failed to connect socket to '/var/run/libvirt/libvirt-sock': Connection refused

I added a virtual network card from a physical network card to the xml file of the virtual machine.

 <devices>
  <interface type='hostdev' managed='yes'>
    <driver name='vfio'/>
    <source>
      <address type='pci' domain='0x0000' bus='0x86' slot='0x0a' function='0x7'/>
    </source>
    <mac address='52:54:00:6d:90:02'/>
  </interface>
  </devices>

When I execute virsh define, I get error info

error: failed to connect to the hypervisor

error: Failed to connect socket to '/var/run/libvirt/libvirt-sock': Connection refused

I tried reinstall libvirt qemu ,but no effect.



Solution 1:[1]

Try these steps:

sudo setfacl -m user:$USER:rw /var/run/libvirt/libvirt-sock

Exit the session and again logged in then,

sudo systemctl enable libvirtd
sudo systemctl start libvirtd

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ali Hassan Ahmed Khan