Autostart on Debian 11 for unpriviledged LXC containers fails

I have created a setup on Debian 11 with unpriviledged LXC containers. I only use LXC, not LXD.

For autostarting the containers I use systemd as described here: ubuntu 14.04 - How to auto-start unprivileged lxc containers? - Server Fault

So i created a user service for system d and that works partly. Strange thing is I have 4 containers and only three are started, when i change the boot order of the containers a different one is missing. i can start it manually without problems.

I can confirm this problem. Have exact same behavior on Debian 11 with LXC version 4.06.
Problem seems to be resolved after upgrade to LXC testing version (4.10).

1 Like

I found a solution, upgrade to testing was not an option for me.

  • create a shell script in /usr/local/bin/start-lxc-containers.sh
#!/bin/sh

for i in $(su - lxc -c "lxc-ls -1"); do
  su - lxc -c "lxc-unpriv-start $i"
done
  • I have a user “lxc” here, put your user in su - $USER

  • create a systemd service in /etc/systemd/service/lxc-start.service:

[Unit]
Description="LXC autostart for lxc user"

[Service]
ExecStart=/usr/local/bin/start-lxc-containers.sh

[Install]
WantedBy=default.target
  • Enable the service
systemctl daemon-reload
systemctl enable lxc-start.service

At the moment I have all containers under the same user, not optimal but still better than root.

Unfortunately, it does not work on boot yet… I can start ist manually okay, but on boot the service does nothing yet…

I answered my own question here: Running pure LXC with unprivileged containers on Debian