Http://blog.csdn.net/azurechina/article/details/27106071
What is custom data?
Customers often ask how scripts or other metadata can be inserted when Microsoft Azure virtual machines are configured. In other clouds, this concept is usually calledUser Data. Microsoftazure also has a similar function, which we callCustom Data.
Custom data is sent to the VM along with other configuration information, such as the new host name, user name, password, certificate, and key. This type of data is base64-encoded and passed to the azure API. In Windows, custom data is stored as a binary file% Systemdrive % \ azuredata \ customdata. Bin. On Linux, custom data is copied to the ovf-env.xml file of the/var/lib/waagent directory when a virtual machine is created. For convenience, the later Microsoft Azure Linux agent will also copy base64 encoded data/Var/lib/waagent/customdata.
What is cloud-init?
Currently, cloud-init is only pre-installed for Ubuntu images in the Microsoft Azure library and is set to process custom data sent during VM creation. This means that for Ubuntu, you can use the cloud-init configuration file to create a VM using custom data, or only send the script that cloud-init will execute at creation. For more information, see Cloud-init.
If cloud-init is not available on the image, you can still use the custom data provided during the pre-installation script or other tools that can read data on the system. In this case, you may install% Systemdrive % \ azuredata \ customdata. Bin(Windows) or/Var/lib/waagent/ovf-env.xml(Linux) File Read script, run the script at startup and decode it to act on Custom Data. After installing the script, you can cancel the configuration of a Windows or Linux image and capture this image for reuse.
Working Principle
Currently, the simplest way to insert custom data to IAAs VM is to use the Windows azure command line tool. Currently, Microsoft Azure powershell cmdlet does not support this function, but it will soon be available in the forthcoming version.
Since the CLI tool Version 0.7.5,-- Custom-Data. This parameter treats the file name as a parameter. The CLI tool then uses base64 to encode the file content and sends it together with the configuration information. The only limit here is that the file size must be smaller than 64 KB; otherwise, azureapi will not accept the request.
The following is a simple example of how to prepare and transmit custom data to the ubuntulinux VM:
In this example,Custom-data.txtIt can be a cloud-init configuration file, or a shell script (as long #! Cloud-init will execute ). Try it.
Other references:
Http://msdn.microsoft.com/en-us/library/windowsazure/jj157186.aspx
Http://blogs.msdn.com/ B /windowsazure/archive/2014/04/21/custom-data-and-cloud-init-on-windows-azure.aspx
Custom Data and cloud-init on Microsoft Azure