Linux – How to supply custom init script to Azure instance

azureinitlinuxscripting

Is it possible to create an instance specific init script and pass it to a virtual machine that is created via the API of Microsoft Azure? I know this from AWS, but could not find a way to do this on MS Azure.

The only workaround I can think of it to create a generic script for my own image that then somehow downloads a custom script based on the hostname.

Best Answer

I posted the answer to this on StackOverflow (link). Reposting here (with a few tweaks) as well, for completeness...

Take a look at the REST API call for creating a Virtual Machine deployment, specifically the <CustomData> element. This lets you inject up to 64K of binary data to your VM during provisioning, which results in a CustomData.bin file being generated inside your VM. This should help you with first-time init, and works with both Linux and Windows Virtual Machines.

Note that this isn't yet implemented in the command-line tools - you'll need to call the API directly. There's now a pull request posted implementing the proper CLI wrapper code for CustomData but it hasn't yet been accepted.

Related Topic