Search code examples
azureazure-virtual-machineazure-cli2

How to create new vm using existing VHD image in blob storage in azure cli 2.0?


We have a custom vhd image in our blob storage and we want to create a new vm using that vhd image through cli 2.0 in azure. Can anyone point me right direction to do so or any suggestions would be appreciated.


Solution

  • We can use this script to create Azure VM, like this:

    az vm create -n MyVm -g jasonvm2 --use-unmanaged-disk --os-type linux --public-ip-address "" --attach-os-disk https://jasonvm2disks653.blob.core.windows.net/vhds/jasonvm220170915094051.vhd
    

    We can use --attach-os-disk to specify the VHD's URL:

    --attach-os-disk
    

    Attach an existing OS disk to the VM. Can use the name or ID of a managed disk or the URI to an unmanaged disk VHD.

    More information about az vm create, please refer to this link.