1

I'm trying to use a tool called SecGen that creates a virtual machine with a random vulnerability for hacking. I'm not using the newer repo because I've been having unrelated issues that I won't state here. Once I run ruby secgen.rb run, i encounter an error that states:

Call to virConnectOpen failed: Failed to connect socket to '/var/run/libvirt/libvirt-sock': No such file or directory`

With some further investigation, have noticed that the file /var/run/libvirt doesnt exist, and when I try to run systemctl start libvirtd (with or without sudo) it comes up with an error stating that it failed to start because the host is down.

A few things to note: I have installed most packages for libvirt using apt-get (including libvirt-clients, libvirt-daemon-system which includes the libvirtd command, and libvirt-dbus). Also, I've installed vagrant (also through apt-get) and Virtualbox (through apt-get and the website for windows 10). Most other files do exist for libvirt within the files.

I do apologies if this question seems vague (as a lot of you like to mention for my questions), however I couldn't find anything upon this subject other than people not finding libvirt-socket in the libvirt file, but my question is a bit more different because of the fact that the file in /var/run doesnt exist at all. I am more than willing to provide any info necessary if asked. id also like to mention I'm using Ubuntu for Windows with WSL.

Edit: Heres the error made by systemctl when starting libvirtd: System has not been booted with systemd as init system (PID 1). Can't operate. Failed to connect to bus: Host is down

4
  • 1
    You could improve your reputation by a number of simple measures, such as not replicating an entire paragraph, adding more paragraphs, formatting code as code and using a spellchecker. Commented Feb 24, 2021 at 1:49
  • Of course /var/run/libvirt is missing when libvirtd is not running. Please add the precise error issued by systemctl start libvirtd to your question, and perhaps journal messages (journalctl -u libvirtd) if they are relevant. I don't think that Vagrant and Virtualbox do anything to libvirtd, but I do wonder whether you can run VMs of any sort in WSL. Commented Feb 24, 2021 at 1:57
  • 1
    It seems that systemd can't be used in WSL out of the box. This has been discussed on Stackoverflow. You need to find another way to start libvirtd. There is also a Serverfault thread about running KVM in WSL2. Seems to be possible in principle, but requires work. Commented Feb 24, 2021 at 2:03
  • I think in addition to what others said, /var/run is a symlink to /run on systemd systems, and /run is a tmpfs filesystem (at least on a real Linux system, not sure about WSL). So systemd-tmpfiles needs to create the directory on boot. Commented Feb 24, 2021 at 2:18

1 Answer 1

0

Debian requires by its policy that a package create directories in /run and /var/run as needed, since these directories may be cleared or created on boot. (As a practical matter, this is also usually the case for Ubuntu.) That can be done by the program itself or the script which starts it. If the service is not running, the directory may not even exist yet.

In WSL, the init system is not systemd. systemd in most distros starts a lot of services and mounts a lot of file systems, neither of which would be useful in most WSL environments. Instead, WSL uses its own custom init system to do just a few things, which means that a WSL system can be booted much, much more quickly.

Since the tools that are shipped with systemd usually steadfastly refuse to run if systemd is not running, you can't use them. You can invoke service libvirtd start instead to try to use an init script which may be shipped with the package. Using the service command has several advantages: it delegates to systemd if systemd is enabled and works with init scripts if it is not, and as such, generally functions on all Linux systems regardless of whether they are using systemd or a different init system. It may be possible that no init script exists, in which case you'll have to handle starting it yourself, which you can do by looking at the configuration in the service file.

3
  • As these solutions make sense, i tried both and came up empty handed, both with service telling me libvirtd isnt a service, and not being able to find an init script nor a hint as to how i should start it. Thanks for the attempt though! Commented Feb 27, 2021 at 1:06
  • There is an init script for it, but you may need to install libvirt-system-daemon. Commented Feb 27, 2021 at 1:46
  • @bk2204 y'know what? You were so close, but you definitely helped my issue! I installed libvirt-daemon-system and now I can run virt-install and other stuff by running libvirtd :) Thank you for the hint! Commented Jul 7, 2021 at 17:45

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.