4

I've been working with systemd-nspawn and have a couple of containers that I'd like to automatically start at system start.

I'm using arch linux and according to the archwiki entry, the following code should do the trick

# systemctl enable systemd-nspawn@MyContainer.service
# systemctl start systemd-nspawn@MyContainer.service

Assuming the container MyContainer is in /var/lib/machines and was created with something like:

# pacstrap -i -c -d /var/lib/machines/MyContainer base

I can start the container with:

# sudo systemd-nspawn -b -D /var/lib/machines/MyContainer

and

# systemctl start systemd-nspawn@MyContainer.service

as well as

# machinectl start MyContainer

but I just can't get the container to start at boot and running sudo systemctl status systemd-nspawn@MyContainer.service right after boot doesn't show any errors. Does anyone know what I need to do? Does there maybe need to be another service running?

flooose
  • 225

1 Answers1

3

After doing a little more research, I discovered the problem. It's not that another service needs to be running, but instead another target, specifically machines.target, so running

systemctl enable machines.target

in addition to the commands above made it so that MyContainer starts at boot.

As a side note, this wasn't immediately clear because when I call

systemctl list-units --all --type=target

on both of my computers (both running arch linux), machines.target is not included in the list. Not sure why, but that was the fix.

flooose
  • 225