Problems setting up LXC

2 posts / 0 new
Last post
#1 Sat, 2017-02-25 00:36
stratacast1
  • stratacast1's picture
  • Offline
  • Last seen: 1 year 1 month ago
  • Joined: 2017-02-25

Hi! I just discovered Alpine Linux and after a bit of noodling around and reading, I have fallen in love with this distro. I'm setting up a project right now that I want to utilize LXC/LXD containers. I see LXD is in the testing repos (which is no big deal to me), but I can't find anything on setting it up. lxd init fails. So I tried to do LXC, and following the instructions proves unfruitful.

https://wiki.alpinelinux.org/wiki/LXC

I can create containers if I don't include the lxc.conf file for networking, but then I don't have networking. Otherwise anything else I try I get these errors:

lxc-start: tools/lxc_start.c main: 360 The container failed to start.
lxc-start: tools/lxc_start.c: main: 362 To get more details, run the container in foreground mode.
lxc-start: tools/lxc_start.c: main: 364 Additional information can be obtained by setting the --logfile and --logpriority options.

So I tried adding --logfile and got this information:

lxc-start 20170224153317.003 ERROR lxc_cgfs - cgroups/cgfs.c:do_setup_cgroup_limits:2037 - No such file or directory - Error setting use to @kernel for test1
lxc-start 20170224153317.003 ERROR lxc_start - start.c:lxc_spawn:1182 - Failed to setup cgroup limits for container "test1".
lxc-start 20170224153317.033 ERROR lxc_start - start.c:__lxc_start:1338 - Failed to spawn container "test1".
lxc-start 20170224153322.075 ERROR lxc_start_ui - tools/lxc_start.c:main:360 - The container failed to start.
lxc-start 20170224153322.076 ERROR lxc_start_ui - tools/lxc_start.c:main:362 - To get more details, run the container in foreground mode.
lxc-start 20170224153322.076 ERROR lxc_start_ui - tools/lxc_start.c:main:364 - Additional information can be obtained by setting the --logfile and --logpriority options.

How do I get this working as it should?

Mon, 2017-02-27 17:31
bestboy69
  • bestboy69's picture
  • Offline
  • Last seen: 1 year 1 month ago
  • Joined: 2017-01-21

Yo I'd been having some problems myself for a script I am making. Just ironed everything out tonight at 6am.

I don't really know what's wrong with your setup, but the way you worded it leads me to believe that the issue might be in which configuration files you're using:

lxc.conf and default.conf (or whatever conf you're using to make your container) aren't interchangeable, as far as I know.
http://man7.org/linux/man-pages/man5/lxc.conf.5.html

lxc.conf is for the program itself; you can specify the dir in which lxc looks for containers, such as changing it from /var/lib/lxc to /lxc/containers, or whatever. Must stay named /etc/lxc/lxc.conf.
https://linuxcontainers.org/lxc/manpages/man5/lxc.system.conf.5.html

default.conf is a configuration file for the individual containers. Can be renamed to anything when the path is specified by lxc-create's -f option.
https://linuxcontainers.org/lxc/manpages/man5/lxc.container.conf.5.html

(The name scheme of these web pages is a little misleading. It appears lxc.conf.5.html is a general summary of the config files, lxc.system.conf.5.html is the 'lxc.conf,' and lxc.container.conf.5.html is what I am referring to as 'default.conf.')

LXC is really picky about its configuration files. If there's an option spelled wrong, it might not even tell you which option it is; never mind adding options for lxc.conf rather than the default.conf. Sometimes you'll just get error 318 with no explanation. I'm still having nightmares.

Using this line:
lxc-create -n files -f /var/lib/lxc/files/config -t alpine

here is a working config which I use:

lxc.arch = x86_64
lxc.include = /usr/share/lxc/config/alpine.common.conf
lxc.utsname = files
lxc.start.auto = 1
 
# I have eth0 set to bridge to br0 in the interfaces file
lxc.network.type = veth
lxc.network.flags = up
lxc.network.link = br0
lxc.network.name = eth0
lxc.network.mtu = 1500
 
#assigned IP from physical router
lxc.network.ipv4 = 0.0.0.0/24
lxc.network.ipv4.gateway = auto
 
#alpine.hostfs is -rbind'd to the system's root
lxc.rootfs = overlayfs:/var/lib/lxc/alpine.hostfs:/var/lib/lxc/files/delta0
#lxc.mount = /var/lib/lxc/fstab.files
lxc.rootfs.backend = overlayfs

Also, setting the --logpriority (-o) to "trace" gives more details than error, which is the default I think.

The biggest problem for myself was figuring out exactly where my filesystems needed to be. They can barely be moved from /var/lib/lxc. Its best to let most directory names/locations stay default, and create a new directory while organising with symlinks.

For my overlayfs setup it's kinda like this:

ln -s /var/lib/lxc/{HOSTFS} /lxc/{OSNAME}/{HOSTFS}
ln -s /var/lib/lxc/{CONTAINERNAME}/delta0 /lxc/{OSNAME}/{CONTAINERNAME}

For non-overlayfs setup you'd just change delta0 to rootfs, i think.

I have a script that makes my containers for me in this manner.

I feel like some of the documentation is incomplete, or that certain bits of information are buried a little too deep.

Log in or register to post comments