Running systemd utilities like systemctl under an nspawn?

5,072

Solution 1

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

Solution 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.
Share:
5,072

Related videos on Youtube

Brandon Condrey
Author by

Brandon Condrey

Consider opposing apartheid in Palestine and signing onto the BDS Movement; #1 User for DBA.SE 2017. Available for contracting: 281.901.0011 PostgreSQL & PostGIS / MySQL / SQL Server JavaScript, Typescript, Rx.js, Node.js, Angular Also: C / Perl / Python / Rust / x86 Assembly

Updated on September 18, 2022

Comments

  • Brandon Condrey
    Brandon Condrey almost 2 years

    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?