Lxc container doesn't autostart

I set up an lxc container and created the section

config container
    option name lms
    option timeout 60

in `/etc/config/lxc-auto. However, the container does not autostart on boot of the router. What am I missing here? Is the fact that the container is stored on a hard disk relevant?

yes. It’s relevant.

Did you change your path for LXC containers in /etc/lxc/lxc.conf? :slight_smile:

No, but I made /srv/lxc a symlink to the lxc directory on the hard disk.


The main question is: does the container start at all?

If I start it via the command line or LuCI, it starts without problems, yes.

OK, then maybe you could try looking at /etc/init.d/lxc-auto?

  • is is enabled? (look at ls /etc/rc.d | grep lxc, and /etc/init.d/lxc-auto enable if not)
  • what happens when you run it manually? (/etc/init.d/lxc-auto start)

Failing that, you could try adding some debug code to /etc/init.d/lxc-auto: use the logger command & look at /var/log/messages.

/etc/init.d/lxc-auto is enabled. When I run it manually, it will correctly start/stop the container.

I’ll try your debugging suggestion later, can’t reboot the router just now. My suspicion would be that lxc-auto runs before the HD is mounted. If that is the case, is there any way to make it depend on the HD? I can always put a sleep in there, but that seems like an ugly solution.

Yes you can - various ways…

a) add a long-enough pause (e.g. sleep 15) to /etc/init.d/lxc-auto to wait until the right file appears (non-deterministic)

b) add a flag to mount point: touch /srv/lxc/FLAG_UMOUNTED and (after mounted) touch /srv/lxc/FLAG_MOUNTED_VFAT (or _EXT4, etc.) and add code to /etc/init.d/lxc-auto to wait until the right file appears (deterministic)

c) increase the START=xx of /etc/init.d/lxc-auto (which is 00) relative to /etc/init.d/mountd (80)

  • or is it /etc/init.d/fstab (40) ?? - I can’t recall.

I generally use a variation/combination of b) plus one of the others…

Actually, I read your post too quickly. I agree a sleep is unsatisfactory, but it is simple.

I also suggested changing the init script, but a better option (especially if only one container is affected) may be to add something to the config file:

root@router:~# cat /etc/config/lxc-auto
config container
option name ‘ubuntu’
list command ‘sleep 15’

1 Like

Sorry, this has partly been my mistake for not remembering my own setup. The lxc path actually sits on a RAID1 which only gets mounted after I execute mdadm --assemble --scan in /etc/rc.local, so it’s no wonder is’s not mounted when S99lxc-auto runs.

I’d like to find the canonical way to mount an md volume at boot, but I’ll open a separate thread for that.

Thanks very much for your help!