How cloud-init systemd service is activated on Ubuntu 16.04 (xenial)

Recently I've trace how cloud-init is being run. First, I try to find service file in /etc/system/system or /lib/systemd/system. Although I can locate the unit files, I can't see any systemd target that will bring up these cloud-init services. I did't see how is activated by systemd.

Finally, I found that cloud-init project utilize the systemd generator to generate the unit files dynamically. The dynamic unit files is located at /run/system/generator.early/ With this unit file, when the is activated by systemd, the will also be activated. Then the systemd will further activate related cloud-init service in /etc/systemd/system/

Below is the dynamic unit file.

$ ll /run/systemd/generator.early/
lrwxrwxrwx 1 root root 37 Jul 14 07:52 /run/systemd/generator.early/ -> /lib/systemd/system/

If I want to disable cloud-init, there are several ways to do it.

  1. Mask the default cloud-init systemd generator.
    ln -sf /dev/null /etc/systemd/system-generator/cloud-init-generator
  2. Add kernel parameter cloud-init=disabled or touch /etc/cloud/cloud-init.disabled. This kernel parameter will be processed by cloud-init systemd generator. See


comments powered by Disqus