1

If I have a directory that I bootstraped with debootstrap that I got inside of running systemd-nspawn what do I have to do make its internal systemd functional?

$ sudo systemd-nspawn -D ./foo
Spawning container mschroot on /opt/foo.
Press ^] three times within 1s to kill container.
root@foo:~# systemctl
Failed to connect to bus: No such file or directory

If I manually try to mount --bind I get a different error,

$ sudo mount --bind /proc /opt/foo/proc
$ sudo chroot /opt/foo/
root@x230:/# systemctl
Running in chroot, ignoring request.

Inside that chroot there is a service installed that I would like to start?

4

If you want to use systemd features inside of your systemd-nspawn containers you need several things

  1. dbus in your container
  2. You need to actual boot the container with systemd-nspawn --boot
2

systemd is being correct here. You're trying to run it from the chroot, but the chroot has an entirely different set of paths, libraries, and services. Allowing you to call systemctl would be a mess: is it the correct D-Bus library? Is the systemctl versions inside the same as the daemon outside?

If all you want to do is use a service inside the chroot, you have two options:

  • Use the new portable services, introduced with systemd 239. If you want the service inside to be accessible from outside, then this is what you want.
  • Make sure systemd is present inside the chroot, and use systemd-nspawn --boot to run a separate systemd instance for inside the chroot. Then, you can enable it, and it will only take effect inside.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.