How to: Clone a Linux Azure VM

In this post we are going to cover how to clone a Linux VM using the Microsoft Azure ARM portal and Azure CLI. In the next post we will use the JSON template and VHD we capture from today’s post to deploy a second VM, and then in a future post, we will cover tying everything together and creating an availability set.

First, you will want to ensure you have Azure CLI installed. You can download it for free here. To start, launch Windows PowerShell, or whichever shell you prefer, and set your configuration mode to ARM. To do so, type:

Next, to login to your Azure account via CLI type:

You can then verify subscriptions available by typing:

Now, you will want to ssh over to the VM you wish to capture. Note: Capturing the VM will require deprovisioning it, generalizing it, and then retiring it. You will not be able to reuse the VM once it has been deprovisioned and generalized. Once you are tunneled into the vm, type the following command to deprovision:

Next, you can use the following script to quickly capture the image and save a JSON template file to a local folder of your choice. Simply fill in the variables with the desired information and run the script after.

 

Reminder: All of my posts are provided "AS IS", imply no warranties, and confer no rights or special privileges. Use of included postings, code samples and other works are subject to the terms specified at Microsoft. For more information, click here.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.