2

As far as I understand it, cloud-init handles early initialization of a cloud/VM instance. Ive been using it to help build KVM VMs and it works really well.

One aspect of cloud-init I don't understand is what happens once its done the initial creation of the instance.

  • Does it automatically disable itself so it never runs again?
  • Can it execute again under certain circumstances (e.g. on a change to /etc/machine-id)? I'm pretty sure I forced it to re-run at some point by running

    sudo rm -rf  /var/lib/cloud/*
    
  • Is it designed so that I should be uninstalling cloud-init once my instance has been built and its gone into production, or does cloud-init stay installed (doing nothing) even after its been instantiated?

1
  • "Initialization" is not the same as "installation".
    – Rinzwind
    Oct 3, 2019 at 7:36

1 Answer 1

1

Embarrassingly the answer I was looking for is in the docs (I swear it wasn't there at the time I asked the question): https://cloudinit.readthedocs.io/en/latest/topics/boot.html#first-boot-determination

cloud-init has to determine whether or not the current boot is the first boot of a new instance or not, so that it applies the appropriate configuration. On an instance’s first boot, it should run all “per-instance” configuration, whereas on a subsequent boot it should run only “per-boot” configuration.

So the answer to my question is that cloud-init (potentially) behaves differently depending on whether the cloud/VM instance is booting for the first time, or a subsequent time.

Furthermore, cloud-init doesn't disable itself (it just runs different steps), and does not need to be removed once its completed its initialisation/installation stage (first boot).

By default, cloud-init attempts to determine which case it is running in by checking the instance ID in the cache against the instance ID it determines at runtime. If they do not match, then this is an instance’s first boot; otherwise, it’s a subsequent boot. Internally, cloud-init refers to this behavior as check.

Thus changing the machine id (/etc/machine-id) will most likely cause cloud-init to re-run the initialisation stage. As will removing the cache (sudo rm -rf /var/lib/cloud/*)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.