When starting a new VPS, you may encounter connection errors related to the libvirt hypervisor service. This typically happens when the libvirtd service is not running on the host system. The error message "failed to connect to the hypervisor" or "No such file or directory" for the libvirt socket indicates that the virtualization service needs to be started before the VPS can be launched.

How to Fix It

  1. Step 1: Check the libvirtd service status

    First, verify whether the libvirtd service is running on your server:

    systemctl status libvirtd.service

    This command will show you if the service is active, inactive, or stopped. If it's not active, proceed to the next step.

  2. Step 2: Start the libvirtd service

    If the service is down or stopped, start it with the following command:

    systemctl start libvirtd.service

    To ensure that the service starts automatically on system boot, enable it using:

    systemctl enable libvirtd.service
  3. Step 3: Verify the socket file existence and permissions

    The libvirt service communicates through a Unix socket. Ensure that the socket file exists at /var/run/libvirt/libvirt-sock. You can check this by running:

    ls -l /var/run/libvirt/

    If the socket file does not exist, there might be an issue with the libvirtd service. Check the logs for more details.

    Additionally, ensure that your user has the necessary permissions to access this socket. You can add your user to the kvm group if you're not already a member:

    sudo usermod -aG kvm $USER

    After adding yourself to the group, log out and back in for the changes to take effect.

  4. Step 4: Launch the VPS from the admin panel

    Once the libvirtd service is running and you have verified that your user has the correct permissions, return to your admin panel and start the VPS. The connection error should now be resolved, and the VPS should start successfully.

Common Issues

  • Service fails to start: If the libvirtd service fails to start, check system logs with journalctl -xe for detailed error messages. This can provide clues about what might be going wrong, such as missing dependencies or configuration issues.
  • Socket permission errors: Ensure your user has the necessary permissions to access /var/run/libvirt/libvirt-sock. Adding your user to the kvm group, as mentioned in Step 3, can resolve these issues. If problems persist, you may need to adjust file permissions or SELinux settings.
  • Configuration errors: Sometimes, incorrect configuration files can prevent libvirtd from starting properly. Check the configuration files located in /etc/libvirt/ for any syntax errors or misconfigurations.

Troubleshooting Tips

  • Restart your server: If you've made changes to system services or configurations, a full server restart can sometimes resolve lingering issues.
  • Check for updates: Ensure that all related packages are up to date. Outdated software can lead to compatibility issues and service failures.