You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/virtual-machines/linux/cloud-init-deep-dive.md
+25-27Lines changed: 25 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,50 +4,50 @@ description: Deep dive for understanding provisioning an Azure VM using cloud-in
4
4
author: mattmcinnes
5
5
ms.service: virtual-machines
6
6
ms.topic: conceptual
7
-
ms.date: 07/06/2020
7
+
ms.date: 03/29/2023
8
8
ms.author: mattmcinnes
9
9
ms.reviewer: cynthn
10
10
ms.subservice: cloud-init
11
11
---
12
12
13
13
# Diving deeper into cloud-init
14
14
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
16
16
17
17
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.
18
18
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.
21
20
22
21
## 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.
24
24
25
25
Some configurations are already baked into Azure Marketplace images that come with cloud-init, such as:
26
26
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:
30
30
31
31
```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
33
36
# to update this file, run dpkg-reconfigure cloud-init
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.
43
43
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.
45
47
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`:
47
49
48
-
These are some of the `cloud_init_modules`:
49
-
50
-
```bash
50
+
```config
51
51
- migrator
52
52
- seed_random
53
53
- bootcmd
@@ -60,18 +60,16 @@ When provisioning with cloud-init, there are 5 stages of boot, which process con
60
60
- update_hostname
61
61
- ssh
62
62
```
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.
67
63
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.
68
65
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.
70
68
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
0 commit comments