I have created a lxc container easily with LXD tools however I couldn't find a way to auto-start it on reboot. (Ubuntu 15.04)
For LXC it's said that adding lxc.start.auto = 1
to the container config would be enough however I couldn't find the config file for the container created with LXD. I tried
lxc config set my_machine raw.lxc "lxc.start.auto=1"
without any luck. The configuration is saved but the container didn't start... Any ideas?
It's a few months later now, and autostart is (for some time now) supported in lxd itself. You can just
Now u1 will autostart on each reboot.
Based on the official documentation here LXC container startup was designed using upstart. As of March 9, 2015 Ubuntu 15.04 changed to systemd by default. More detail regarding the impact of this change and how to switch from systemd to upstart and back again is available on this page.
To check to see if your system is using systemd vs. upstart you can test by issuing the command
sudo initctl version
which will return upstart if upstart is handling init. another useful method is to issue the commanddpkg -S /sbin/init
which will tell you which package installed it (in my case on 14.04 it's upstart) you you can find more very good answers on how to do so from our friends at Unix & Linux. Further detail regarding identifying the init system is also available.To see if your LXC container auto-starts under upstart as designed, you can install the upstart-sysv package, which will remove ubuntu-standard and systemd-sysv (but should not remove anything else. Give the developers a heads up if it does!), and run sudo update-initramfs -u. After that, grub's "Advanced options" menu will have a corresponding "Ubuntu, with Linux ... (systemd)" entry where you can do an one-time boot with systemd.
You can revert back to systemd installing systemd-sysv and ubuntu-standard packages.
Further sources (not linked elsewhere):
https://unix.stackexchange.com/questions/196166/how-to-find-out-if-a-system-uses-sysv-upstart-or-systemd-initsystem
I asked the lxc/lxd developers themselves and it appears that it's not possible to do it with configuration if lxd is used to create the containers. It's not implemented yet, but planned they say...
lxd is somewhat different from lxc scripts: i.e. the default directory for the containers is
/var/lib/lxd/lxc/
instead of/var/lib/lxc/
and the container configurations are held in a central sqlite db instead of some config file per container.So I had to create a systemd job by creating the file:
/etc/systemd/system/multi-user.target.wants/lxd-autostart.service
with this content:and
/usr/local/bin/lxd-autostart-check.sh
is: