Create symlink in stopped container

I can provide a firstboot script to a new Alpine Linux container before starting it so that the script is launched on boot to provision it. I do two things:

  • copy the script to /etc/init.d/firstboot
  • symlink it to /etc/runlevels/default

The first is easy, using lxc file push, the second uses curl as @stgraber suggested in 2017, like this:

curl --unix-socket /var/lib/lxd/unix.socket -s lxd/1.0/containers/mycontainer/files?path=/etc/runlevels/default/firstboot -H "X-LXD-type: symlink" -H "Content-Type: text/plain" -d "/etc/init.d/firstboot"

Is that still the way to do this in 2022, or is there a better way ?

Still the best way. LXD 4.24 will introduce a different way to handle this though I’m not sure that it would be necessarily easier.