1. Home
  2. Training Library
  3. Microsoft Azure
  4. Courses
  5. Create and Manage Virtual Machines for Azure 70-532 Certification

Create and Manage VM Images


Overview4m 31s
Start course


Course Description

This course will show you how to create and manage virtual machines in the Azure ecosystem. 

Course Objectives

By the end of this course, you'll have gained a firm understanding of the key components that comprise the Azure virtual machine ecosystem. Ideally, you will achieve the following learning objectives:

  • How to create and manage virtual machines in the Azure environment. 
  • How to create and manage VM images, workloads, and more. 
  • How to monitor your Azure virtual machines. 

Intended Audience

This course is intended for individuals who wish to pursue the Azure 70-532 certification.


You should have work experience with Azure and general cloud computing knowledge.

This Course Includes

  • 59 minutes of high-definition video.
  • Expert-led instruction and exploration of important concepts surrounding Azure virtual machines.

What You Will Learn

  • The concepts behind VM workloads.
  • How to create and manage Azure VM images.
  • Azure VM configuration management.
  • Azure VM networking.
  • How to scale Azure virtual machines.
  • How to design and implement Azure VM storage.
  • How to monitor your Azure virtual machines.  


Hello, and welcome back. In this section, we'll cover the creation and management of VM images.

We'll start by giving an overview of what VM images are, and their relationship with different components that form an image. We'll then discuss the different ways in which to prepare an image, how to create one, and finally, how to migrate images between different data centers.

When we created a VM earlier, it was using a preview image from the marketplace. Now let's look at creating our own images. It's important before we go forward to understand the relationship between the three main components of a VM image.

First is the VHD. This is essentially the file format the data uses by a virtual machine. This is then hosted within a disk, which can in turn be attached to a virtual machine. With these components, we can then create a VM image, which can be used as a template to create other VMs with the same shape.

As your virtual machines have two types of disks, operating system OS disks, or data disks. Both are stored as blobs behind the scene, in an Azure Storage account. You can attach multiple data disks to a specific virtual machine, and also upload your own local VHDs to Azure, and connect a disk to a VM.

Having created an image as a template, what do we do when we wish to create new copies of the same VM? We might not want to recreate the machine exactly, for instance, we might want a different machine name for every VM based on the same template. So how would we do that? Well, Azure VMs come in two forms: specialized, and generalized. Specialized images are designed from running one at a time, every time you provision a VM, it's an exact point-in-time copy from the image. A generalized image, on the other hand, is more flexible and can be used to provision a whole cluster of images that have the same core image, but are configured slightly differently. For instance, different machine names.

We'll now review the steps to create a custom VM image, based on one that we've taken from the Azure marketplace. First we create a VM taken from the marketplace, and then we customize and generalize it if necessary, and then we take a snapshot of the image. This is known as capturing the image. Then we can instantiate new virtual machines based on that captured image.

Alternatively, if you're working with a local VHD on premise, then we'll need to do some more work upfront to create the source VM image for us to work from, essentially getting the existing VHD into Azure, from where we can build a virtual machine, that we can customize as previous. However, note that VHD is the only format supported by Azure. VHDX is not supported.

This diagram illustrates the two models previously shown. Firstly, we can create a VM based on the image from the gallery or marketplace, but we can also supply a local VHD, wrap it in a disk, and then supply that to the virtual machine.

Let's look at how to upload a VHD into Azure through PowerShell, before a demo showing how to attach the VHD to an Azure VM. The first step is authenticating with Azure. One way to do this is through a publish settings file through the command shown here. The first command will open a browser window, and take you to a website that will prompt you to authenticate into Azure and download the publish settings to your local machine. Second line will then import that file.

The alternative is to authenticate directly with Azure from PowerShell. However, with a publish settings file, you can use that repeatedly without having to authenticate, for example, on other machines. Once you've authenticated, you can choose the subscription and storage account that the VHD will be uploaded to. Finally, having created the VHD container, you can execute the Add-AzureVhd command to add the cademo.vhd file into the Cloud Academy storage account. Obviously when you try this, the account name and VHD file name will be different.

In this demo, we'll illustrate how to attach a VHD that we previously uploaded to an existing virtual machine. I'm here in the Azure portal, and now we're going to locate the disk section under the settings for our new VM. So click on the new VM. Wait for the settings to pop up; then we can select Disks. You'll notice that the existing operating system disk is the only one that's been attached. Go to the menu at the top, select Attach existing. We'll then navigate through the location where the VHD was uploaded. And select OK, and then we are presented with the screen once we've done that. And now we've selected our VHD. Click OK, and it's now attaching our disk to the virtual machine. So once that attaches, we can go to our VM, and we can connect to the virtual machine. And we can see the other VHD has been loaded, and I have a little message inside, and it says, "Here is some data in a VHD." That concludes the first demo.

Before moving on, let's quickly look at how to attach a VHD to a virtual machine via PowerShell. Firstly, you can mark a VHD as a data disk using the Add-AzureDisk command. Simply specify the disk name, location, and label. If the VHD is an operating system disk, simply add the OS parameter, specifying either Windows or Linux as needed.

Lastly, let's look at attaching a data disk to an existing VM through PowerShell. You can use the Add-AzureDataDisk command to connect an existing data disk to a VM. In this sample, we're getting a handle to the VM first, and then piping that into Add-AzureDataDisk command, before finally calling Update-AzureVM to persist the changes. In this demo, we'll illustrate how to generalize an existing VM, so that we can create a reusable VM image. We'll then see how you can capture that image before creating a brand new virtual machine based on that generalized image.

We've now logged into our VM hosted in Azure. We'll now generalize the VM so we can use it as a template for future virtual machines. To do that, first of all, bring up the Run command prompt, and then type sysprep, and press enter. Once we're here, we'll select the out of the box experience for cleanup action, and then the Generalize checkbox. We'll now select the Shutdown Option, and now the VM is ready to be captured in a generalized state. Note that in Linux, the process is similar except we use the waagent with a flag of -deprovision command. Once you've done that, select OK. And Sysprep will be on its way working. We can go to the Azure portal, and get started on the other side of things.

We'll now look at capturing that virtual machine as an image. We'll select the Capture option at the top, and then we'll populate the fields as needed. So we'll give it a name, and we'll give it a label of captured, and we'll put in the date of today, which is the fifteenth of the eighth, 2016. Now we've captured the image, we can create a new virtual machine based on that image. And now we click on More Services. At the bottom there we'll see VM images Select that. We can see ca-demo-capture. We can click on that. And we can create a new VM. We'll populate the options, and we'll say that this one is a cloned-ca-vm. And click OK. We've now created a new virtual machine based on our generalized image.

Let's just review how to perform the same tasks around VMs that we just saw in Azure through PowerShell. Firstly, we can capture an image using the Save-AzureVMImage command as shown here. Secondly, we can create a new virtual machine based on the saved image, using the Save-AzureVMImage command. We can also do this for a Linux image as shown here.

There are times when you might want to create a VM in one Azure data center, for example West US, but the image resides in another data center, such as North Europe. In such a situation, you'll need to copy the image from the North Europe storage account to the West US one. The easiest way to accomplish this is to use the AzCopy tool. This is a freely distributable tool that makes use of the Azure copy blob API to copy data from one storage account to another in the background, without using your local network. This makes it ideal for copying large files.

Once you've downloaded the AzCopy program, you can simply provide it with the source and destination account URLs and a file pattern to copy, and the source and destination account keys. In this case, I'm using AzCopy to copy thumbnail zip between the caeurope and the caamerica storage accounts. You'll see that once the file is completed, we're presented with a summary of how many files were copied, and how long the operation took.

Stay tuned for the next section, where we'll cover configuration management of the Azure virtual machine offering.

About the Author

Isaac has been using Microsoft Azure for several years now, working across the various aspects of the service for a variety of customers and systems. He’s a Microsoft MVP and a Microsoft Azure Insider, as well as a proponent of functional programming, in particular F#. As a software developer by trade, he’s a big fan of platform services that allow developers to focus on delivering business value.