次の方法で共有


Creating and re-using custom virtual machine images in Windows Azure

Windows Azure provides a set of gallery images for us to use when provisioning virtual machines, but in real world scenarios, depending on the type of environment you want to provision you will most likely have to use a custom image instead of gallery image. There are two options to do this you can build the image on premise and upload it to windows azure using the “CSUpload” tool or create the image in Windows Azure itself. This is the path I chose.

High level steps

  • Create a new stand alone virtual machine in Windows Azure. You can use management portal or Windows Azure PowerShell CmdLets
  • RDP into this Virtual Machine once it’s ready, for the purposes of this post I am creating a base image to be used for provisioning SharePoint 2010 farms so my goal is to have all the required software, scripts etc. available in the VM itself so I can just kick it off after I provision my SharePoint VMs in the cloud
  • Once you have everything you need in your base Virtual Machine, follow the instructions in article to capture an image

 

Once the custom image is successfully created, you will need to backup the associated VHD into another storage account so you can recover from it every time you build environment in Azure. This way in your teardown script for the environment you can just simply blow away everything in the storage account and you wont lose the time and effort you put in creating the custom image.

To copy/move VHD between storage accounts I used a tool called Windows Azure VHD helper built by Stephen W. Thomas. You can get this tool from here. After you make a copy of VHD in a backup storage account you can simply blow away the custom image you created through management portal or using Windows Azure PowerShell CmdLets

When you are ready to use your base image for new environment you are provisioning, simply copy the VHD back into storage account created for the new environment, VHD for custom images need to be in the same storage account as the VMs that are being provisioned, if not the VM provisioning will fail. After the VHD is copied you can simply use following PowerShell to create the custom image.

 Add-AzureVMImage -ImageName {replace with image Name} -MediaLocation {replace with full url for the VHD file} -OS Windows

Cheers,

</Ram>