Is it possible to statically link lxc 4.0?

Hi,
I get an embedded system ,which has limited ram/disk/core, and running in a 2.6.35 kernel with a 2.11 glib environment. It’s a production environment, a lot legacy app running on it, I can’t upgrade them all.
I am gonna to try an alternative way, to statically link the lxc 4.0, but I met some problem , if I tried to make environment variables like “CFLAGS=”-static -static-libgcc -static-libstdc++" LDFLAGS="-static-libgcc -static-libstdc++ -static" ,but still failed to get them statically linked. I even tried to chang the flags in Makefile hard coded, didn’t work either.
And I also googled some project use libtool had the similar problem, they suggest to hard code cflags in to CC environment variable, but that didn’t work for LXC.
Beside, I have successfully running the lxc on the chroot. LXC is really a nice ligthweight tool for embedded system.

@brauner is it possible to statically link lxc? thanks

What are the errors you’re seeing? I would expect it’s difficult because
of us making use of libc functions that use nsswitch which is almost
impossible to use in static binaries afair.

Christian

Hi Brauner,
Thanks for the info.
Even after I tried fill in the statically CFLAGS/LDFLAGS, after the whole building process,all the apps are still dynamically linked(I am using armv7 gnu libc).
Later I turned to musl, but haven’t tried statically linked yet, for now I am running lxc in the chroot environment which is an alternative way, so far so good.

BTW: I met another strange problem, lxc 4.0.6, kernel 2.6.35 with cgroup patch

  1. Trace log:
    lxc-start x11vnc 20210122095620.193 INFO start - start.c:lxc_init:837 - Container “x11vnc” is initialized
    lxc-start x11vnc 20210122095620.193 WARN cgfsng - cgroups/cgfsng.c:cgroup_tree_create:1168 - No error information - The /sys/fs/cgroup/openrc//lxc.monitor.x11vnc cgroup already existed
    lxc-start x11vnc 20210122095620.193 DEBUG cgfsng - cgroups/cgfsng.c:cgfsng_monitor_create:1355 - Failed to create cgroup “(null)”
    lxc-start x11vnc 20210122095620.193 WARN cgfsng - cgroups/cgfsng.c:cgroup_tree_create:1168 - No error information - The /sys/fs/cgroup/openrc//lxc.monitor.x11vnc-1 cgroup already existed
    lxc-start x11vnc 20210122095620.193 DEBUG cgfsng - cgroups/cgfsng.c:cgfsng_monitor_create:1355 - Failed to create cgroup “(null)”
    lxc-start x11vnc 20210122095620.193 INFO cgfsng - cgroups/cgfsng.c:cgfsng_monitor_create:1368 - The monitor process uses “lxc.monitor.x11vnc-2” as cgroup
    lxc-start x11vnc 20210122095620.194 ERROR cgfsng - cgroups/cgfsng.c:cgfsng_monitor_enter:1504 - Invalid argument - Failed to enter cgroup “/sys/fs/cgroup/openrc//lxc.monitor.x11vnc-2”
  2. I found in kernel 2.6.35 's cgroup’s doc, said the ‘cgroup.procs’ should be a read-only node for now, but function 'cgfsng_monitor_enter ’ is trying to write data to it, that’s why I always failed to enter the monitor group.
  • cgroup.procs: list of tgids in the cgroup. This list is not
    guaranteed to be sorted or free of duplicate tgids, and userspace
    should sort/uniquify the list if this property is required.
    This is a read-only file, for now.

ret = lxc_writeat(h->cgfd_mon, “cgroup.procs”, monitor, monitor_len);
if (ret)
return log_error_errno(false, errno, “Failed to enter cgroup “%s””, h->monitor_full_path);

Building the tools lxc-attach, lxc-start etc. completely static is a bit of work but I’ll see if we can support it in a good way.

The cgroup issue I’m very tempted to say that a 2.6.35 kernel is super ancient and will likely be problematic in a bunch of other ways. It’s just too old.

Hi Brauner,
That’s right, 2.6.35 is super super old. But the fact is I can’t upgrade the kernel right now , I 'll find a way to do some kernel patch myself.

Anyhow, thanks all the same.

I have a branch that makes it possible to compile all binaries statically and it’s quite a hazzle to get this right with autotools:

2 Likes

:100:
Much appreciate!