Skip to content

Commit a007f45

Browse files
authored
Merge pull request #232652 from divargas-msft/patch-5
[Doc-a-thon] Updating cloud-init-deep-dive
2 parents 2afa588 + a3319e6 commit a007f45

File tree

1 file changed

+25
-27
lines changed

1 file changed

+25
-27
lines changed

articles/virtual-machines/linux/cloud-init-deep-dive.md

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,50 @@ description: Deep dive for understanding provisioning an Azure VM using cloud-in
44
author: mattmcinnes
55
ms.service: virtual-machines
66
ms.topic: conceptual
7-
ms.date: 07/06/2020
7+
ms.date: 03/29/2023
88
ms.author: mattmcinnes
99
ms.reviewer: cynthn
1010
ms.subservice: cloud-init
1111
---
1212

1313
# Diving deeper into cloud-init
1414

15-
**Applies to:** :heavy_check_mark: Linux VMs :heavy_check_mark: Flexible scale sets
15+
**Applies to:** :heavy_check_mark: Linux VMs :heavy_check_mark: Flexible scale sets
1616

1717
To learn more about [cloud-init](https://cloudinit.readthedocs.io/en/latest/index.html) or troubleshoot it at a deeper level, you need to understand how it works. This document highlights the important parts, and explains the Azure specifics.
1818

19-
When cloud-init is included in a generalized image, and a VM is created from that image, it will process configurations and run through 5 stages during the initial boot. These stages matter, as it shows you at what point cloud-init will apply configurations.
20-
19+
When cloud-init is included in a generalized image, and a VM is created from that image, it processes configurations and run-through five stages during the initial boot. These stages matter, as it shows you at what point cloud-init applies configurations.
2120

2221
## Understand Cloud-Init configuration
23-
Configuring a VM to run on a platform, means cloud-init needs to apply multiple configurations, as an image consumer, the main configurations you will be interacting with is `User data` (customData), which supports multiple formats. For more information, see [User-Data Formats & cloud-init 21.2 documentation](https://cloudinit.readthedocs.io/en/latest/topics/format.html#user-data-formats). You also have the ability to add and run scripts (/var/lib/cloud/scripts) for additional configuration, below discusses this in more detail.
22+
23+
Configuring a VM to run on a platform, means cloud-init needs to apply multiple configurations, as an image consumer, the main configurations you interact with is `User data` (customData), which supports multiple formats. For more information, see [User-Data Formats & cloud-init 21.2 documentation](https://cloudinit.readthedocs.io/en/latest/topics/format.html#user-data-formats). You also have the ability to add and run scripts (/var/lib/cloud/scripts) for other configuration.
2424

2525
Some configurations are already baked into Azure Marketplace images that come with cloud-init, such as:
2626

27-
1. **Cloud data source** - cloud-init contains code that can interact with cloud platforms, these are called 'datasources'. When a VM is created from a cloud-init image in [Azure](https://cloudinit.readthedocs.io/en/latest/reference/datasources/azure.html#azure), cloud-init loads the Azure datasource, which will interact with the Azure metadata endpoints to get the VM specific configuration.
28-
2. **Runtime config** (/run/cloud-init)
29-
3. **Image config** (/etc/cloud), like `/etc/cloud/cloud.cfg`, `/etc/cloud/cloud.cfg.d/*.cfg`. An example of where this is used in Azure, it is common for the Linux OS images with cloud-init to have an Azure datasource directive, that tells cloud-init what datasource it should use, this saves cloud-init time:
27+
* **Cloud data source** - cloud-init contains code that can interact with cloud platforms, these codes are called 'datasources'. When a VM is created from a cloud-init image in [Azure](https://cloudinit.readthedocs.io/en/latest/reference/datasources/azure.html#azure), cloud-init loads the Azure datasource, which interacts with the Azure metadata endpoints to get the VM specific configuration.
28+
* **Runtime config** (/run/cloud-init).
29+
* **Image config** (/etc/cloud), like `/etc/cloud/cloud.cfg`, `/etc/cloud/cloud.cfg.d/*.cfg`. An example of where this configuration is used in Azure, it's common for the Linux OS images with cloud-init to have an Azure datasource directive that tells cloud-init what datasource it should use, this configuration saves cloud-init time:
3030

3131
```bash
32-
/etc/cloud/cloud.cfg.d# cat 90_dpkg.cfg
32+
sudo cat /etc/cloud/cloud.cfg.d/90_dpkg.cfg
33+
```
34+
35+
```output
3336
# to update this file, run dpkg-reconfigure cloud-init
3437
datasource_list: [ Azure ]
3538
```
3639

37-
3840
## Cloud-init boot stages (processing configuration)
3941

40-
When provisioning with cloud-init, there are 5 stages of boot, which process configuration, and shown in the logs.
41-
42-
1. [Generator Stage](https://cloudinit.readthedocs.io/en/latest/topics/boot.html#generator): The cloud-init systemd generator starts, and determines that cloud-init should be included in the boot goals, and if so, it enables cloud-init.
42+
When you are provisioning VMs with cloud-init, there are five stages of boot, which process configuration, and shown in the logs.
4343

44-
2. [Cloud-init Local Stage](https://cloudinit.readthedocs.io/en/latest/topics/boot.html#local): Here cloud-init will look for the local "Azure" datasource, which will enable cloud-init to interface with Azure, and apply a networking configuration, including fallback.
44+
1. [Generator Stage](https://cloudinit.readthedocs.io/en/latest/topics/boot.html#generator): The cloud-init systemd generator starts, and determines that cloud-init should be included in the boot goals, and if so, it enables cloud-init.
45+
2. [Cloud-init Local Stage](https://cloudinit.readthedocs.io/en/latest/topics/boot.html#local): Here cloud-init looks for the local "Azure" datasource, which enables cloud-init to interface with Azure, and apply a networking configuration, including fallback.
46+
3. [Cloud-init init Stage (Network)](https://cloudinit.readthedocs.io/en/latest/topics/boot.html#network): Networking should be online, and the NIC and route table information should be generated. At this stage, the modules listed in `cloud_init_modules` in `/etc/cloud/cloud.cfg` runs. The VM in Azure is mounted, the ephemeral disk is formatted, the hostname is set, along with other tasks.
4547

46-
3. [Cloud-init init Stage (Network)](https://cloudinit.readthedocs.io/en/latest/topics/boot.html#network): Networking should be online, and the NIC and route table information should be generated. At this stage, the modules listed in `cloud_init_modules` in /etc/cloud/cloud.cfg will be run. The VM in Azure will be mounted, the ephemeral disk is formatted, the hostname is set, along with other tasks.
48+
The following are some of the `cloud_init_modules`:
4749

48-
These are some of the `cloud_init_modules`:
49-
50-
```bash
50+
```config
5151
- migrator
5252
- seed_random
5353
- bootcmd
@@ -60,18 +60,16 @@ When provisioning with cloud-init, there are 5 stages of boot, which process con
6060
- update_hostname
6161
- ssh
6262
```
63-
64-
After this stage, cloud-init will signal to the Azure platform that the VM has been provisioned successfully. Some modules may have failed, not all module failures will result in a provisioning failure.
65-
66-
4. [Cloud-init Config Stage](https://cloudinit.readthedocs.io/en/latest/topics/boot.html#config): At this stage, the modules in `cloud_config_modules` defined and listed in /etc/cloud/cloud.cfg will be run.
6763

64+
After this stage, cloud-init sends a signal to the Azure platform that the VM has been provisioned successfully. Some modules may have failed, not all module failures result in a provisioning failure.
6865

69-
5. [Cloud-init Final Stage](https://cloudinit.readthedocs.io/en/latest/topics/boot.html#final): At this final stage, the modules in `cloud_final_modules`, listed in /etc/cloud/cloud.cfg, will be run. Here modules that need to be run late in the boot process run, such as package installations and run scripts etc.
66+
4. [Cloud-init Config Stage](https://cloudinit.readthedocs.io/en/latest/topics/boot.html#config): At this stage, the modules in `cloud_config_modules` defined and listed in `/etc/cloud/cloud`.cfg runs.
67+
5. [Cloud-init Final Stage](https://cloudinit.readthedocs.io/en/latest/topics/boot.html#final): At this final stage, the modules in `cloud_final_modules`, listed in `/etc/cloud/cloud.cfg`, runs. Here modules that need to be run late in the boot process run, such as package installations and run scripts etc.
7068

71-
- During this stage, you can run scripts by placing them in the directories under `/var/lib/cloud/scripts`:
72-
- `per-boot` - scripts within this directory, run on every reboot
73-
- `per-instance` - scripts within this directory run when a new instance is first booted
74-
- `per-once` - scripts within this directory run only once
69+
- During this stage, you can run scripts by placing them in the directories under `/var/lib/cloud/scripts`:
70+
- `per-boot` - scripts within this directory, run on every reboot
71+
- `per-instance` - scripts within this directory run when a new instance is first booted
72+
- `per-once` - scripts within this directory run only once
7573

7674
## Next steps
7775

0 commit comments

Comments
 (0)