Automating raid0 MDADM volume creation on a Linux VM when using a custom image in Azure

In this blog post we are looking into one of the multiple ways to automate the process of adding Azure data disks as a single raid 0 volume when using custom images in Azure.


There are a number of ways to automate this process, in this post we are showing one way when you’re using a custom Linux image in Azure. Customizing an Azure marketplace Linux image is a very common scenario in Azure and since this customization process is happening anyways, this example shows how to create this new volume as a raid 0 device and mount it while deploying the VM without the need to rely on Azure VM Custom Script Extension for example.

This post assumes you are starting the customization process from a master VM deployed in Azure with an image from the marketplace (this example was tested with CentOS 7.6 from Rogue Wave Software), this simplifies the image build process. If this is not the case, the Prepare a CentOS-based virtual machine for Azure and Information for Non-endorsed Distributions documents can help you with more detailed information.

Most of the steps outlined here will be showed only as highlevel tasks, if using the same Azure image as mentioned before, you can refer to How to create an image of a virtual machine or VHD document for more detailed information.


  1. Deploy a CentOS 7.6 VM from the marketplace as your master image VM, choosing at least a Standard_D4S_v3 to be able to use Accelarated Networking (
  2. Attach the data disks manually or if you prefer, use Azure Cloud Shell and download the script that helps automating this task by downloading it and executing from within Cloud Shell.

  3. SSH into the newly deployed VM (

  4. Download these two (and change attribute to eXecute) scripts from within the VM.

  5. Install the script to be executed from cron after VM gets started (or rebooted).

    Note: the three arguments states the mount point of the new raid 0 volume, the file system type (ext4 or xfs) and the number of data disks this custom image have, in this example 8 data disks. It is very important to set the number of disks with the same number of data disks you are attaching before generating the image.

    IMPORTANT: After downloading script, please review the mount options it configures before capturing the image since those on my sample script may not meet your needs, therefore you have the opportunity to change it as needed.

  6. Check if script was copied to /root folder and that there is an entry on cron to execute this script at reboot.

    Result: checking-script-and-cron

  7. Deprovision this VM so it can be captured

  8. Back to the Azure Cloud Shell, execute the following commands in order to create your image Example

Note: When deploying this image, bear in mind that in this case, the data disk creation will happen in the background and any other automation you put in place after the VM is deployed should test/wait for the availability of this raid 0 volume’s mount point.

Deploying a VM from custom image using Azure CLI

Now that you have your image created, you can use Azure CLI to deploy a new VM from this custom image. This example deploys a VM attaching to an existing virtual network (no public access is definied here nor network security group for the sake of the example only). This can also be achieved via Templates, Powershell or Azure Portal.

From Azure Cloud Shell:

  1. Create a NIC (we are enabling Accelerated Networking).

  2. Deploy VM from new custom image.

Note: above commands requires that the vnet and image be in the same resource group.

The following blog post shows an example on how to deploy this custom image using the Azure portal.


Written on February 20, 2019