Container has no services, no network, nothing works

Hello.

I installed LXD on gentoo (systemd-based.) LXD/LXC are version 3.16. I did lxd init and this resulted in this configuration:

config: {}
description: Default LXD profile
devices:
  eth0:
    name: eth0
    nictype: bridged
    parent: lxdbr0
    type: nic
  root:
    path: /
    pool: default
    type: disk
name: default
used_by:
- /1.0/containers/ubuntu1804

I installed ubuntu 18.04:

lxc launch ubuntu:18.04 ubuntu1804

There is no ipv4 address though:

# lxc list
+------------+---------+------+-----------------------------------------------+------------+-----------+
|    NAME    |  STATE  | IPV4 |                     IPV6                      |    TYPE    | SNAPSHOTS |
+------------+---------+------+-----------------------------------------------+------------+-----------+
| ubuntu1804 | RUNNING |      | fd42:137a:cb20:5884:216:3eff:fe6c:ca42 (eth0) | PERSISTENT | 0         |
+------------+---------+------+-----------------------------------------------+------------+-----------+

I want to ssh into it, so I did:

$ ssh root@fd42:137a:cb20:5884:216:3eff:fe6c:ca42
ssh: connect to host fd42:137a:cb20:5884:216:3eff:fe6c:ca42 port 22: Connection refused

So I started a shell directly and tried to start sshd:

lxc exec ubuntu1804 -- /bin/bash
root@ubuntu1804:~# systemctl start sshd.service
System has not been booted with systemd as init system (PID 1). Can't operate.
root@ubuntu1804:~# ps aux
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root           1  0.0  0.0  76392  5464 ?        Ss   14:27   0:00 /sbin/init
root           5  0.0  0.0  21900  3892 ?        Ss   14:27   0:00 /bin/bash
root          17  0.0  0.0  37796  3204 ?        R+   14:28   0:00 ps aux
root@ubuntu1804:~# ping 1.1.1.1
connect: Network is unreachable

There is nothing running in it! It didn’t actually boot anything. No services, no internet, no nothing. Am I doing something wrong?

I had to:

mount -t cgroup -o none,name=systemd systemd /sys/fs/cgroup/systemd

on the host. Then it works. However, ubuntu 18.04 was a just a test. What I actually want is a 32-bit ubuntu 16.04. And that one still doesn’t work. lxc launch ubuntu-daily:16.04/i386 ubuntu32 installs and launches it, but then:

# lxc console ubuntu32 --show-log

Console log:

systemd 229 running in system mode. (+PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ -LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD -IDN)
Detected virtualization lxc.
Detected architecture x86.

Welcome to Ubuntu 16.04.6 LTS!

Set hostname to <ubuntu32>.
Failed to read AF_UNIX datagram queue length, ignoring: No such file or directory
Failed to install release agent, ignoring: Permission denied
Failed to create /init.scope control group: Permission denied
Failed to allocate manager object: Permission denied
[!!!!!!] Failed to allocate manager object, freezing.
Freezing execution.

Hi!

Have you followed the instructions at https://wiki.gentoo.org/wiki/LXD#Troubleshooting ?
That is the page that talks about the mount -t cgroup ... line you tried above.

Yes. It’s where I found out I need to mount /sys/fs/cgroup/systemd. This helped with the ubuntu 18.04 container. It doesn’t help with the 16.04 one.

Most likely, you are affected by this, https://github.com/systemd/systemd/issues/9563
It is about nspawn, which is similar to LXC/LXD. But the error you get is the same, bad mismatch between versions of systemd between the host and the container.

The Ubuntu 16.04 container image has

$ systemd --version
systemd 229
+PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ -LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD -IDN

What version does your gentoo host have?

The Troubleshooting page for LXD at gentoo mentions compatibility issues when you use the default OpenRC init/rc system. It is strange that you had to perform the mount even when you are using systemd. I suppose you have used the instructions at https://wiki.gentoo.org/wiki/Systemd to switch init/rc.

Yep. I followed the guide to the letter. The version installed on my system is:

$ systemctl --version
systemd 244 (244)
+PAM -AUDIT -SELINUX +IMA -APPARMOR +SMACK -SYSVINIT +UTMP
-LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL -XZ +LZ4 +SECCOMP +BLKID
-ELFUTILS +KMOD +IDN2 -IDN +PCRE2 default-hierarchy=unified

Systemd has been working without issues since 2016 when I did the switch. OpenRC is not even installed anymore. However, I do not know who or what is responsible for mounting /sys/fs/cgroup/systemd. Is it me in /etc/fstab? Doesn’t seem possible because it needs an mkdir first. Is systemd supposed to do that? Or some systemd service? I can’t find any information about it :-/

In the nspawn bug, I found UNIFIED_CROUP_HIERARCHY=0 so I exported that in the same root shell I use to lxc start ubuntu32, but it didn’t help. Same issue.

There’s also this:

systemd.legacy_systemd_cgroup_controller=yes

It’s supposed to be set via Parameters=. Not sure where to set that in this case though.