Contact

Technology

Nov 11, 2013

Moving a System or Drive to Windows Azure

Bobby Crotty

Bobby Crotty

Default image background

Windows Azure is an excellent place to host development and test environments because you can pay as you go for what you use rather than paying the large upfront cost of hardware that often sits idle once the project goes into production. A few clicks will start a fresh virtual machine on the Windows Azure Management Portal, but if development started locally, the portal offers no way to move your system into the cloud. Thankfully Windows Azure PowerShell allows you to upload virtual hard disk (VHD) files for use with Windows Azure virtual machines (VM).

PREREQUISITES

You’ll need a Windows Azure subscription with a management certificate installed. You can create a self-signed X.509 v3 certificate in IIS or Visual Studio. You need a hypervisor that supports the VHD format. I’ll be using Microsoft’s Hyper-V, but there are several other solutions that will work.

If you want to move a physical machine into Windows Azure, use the Disk2vhd utility to create a VHD copy of your hard drive. See Jeff Hicks’s blog for how to do that. Also, Windows Azure does not support the VHDX format yet. If your disk is in that format, you can click Edit Disk… in Hyper-V, locate your disk, and choose the convert option.

Custom-disk

CREATE A WINDOWS AZURE STORAGE ACCOUNT AND CONTAINER

Now we need somewhere to put the VHD in Windows Azure. If you do not already have a Windows Azure storage account and container, log in to the Windows Azure Management Portal. Click the New button on the bottom left and click Data Services > Storage > Quick Create. Type in a globally-unique URL for the storage account, choose the Location/Affinity Group and Geo-Replication settings that best suit your needs.

custom-disk-2

On the left, click Storage, and then click the storage account you just created. Click Containers at the top of the page, and click Add at the bottom middle. Choose a name for the container and under Access choose Private unless you want the container to be publically accessible. Click the checkmark on the bottom right of the popup and wait for the container to be created. From the list of containers, save the URL of the container you just created.

custom-disk-3

CONNECT POWERSHELL TO WINDOWS AZURE

Previously you had to use the Windows Azure command prompt to upload VHD files, but using PowerShell is now the preferred method. Install and run Windows Azure PowerShell. Run the command Get-AzurePublishSettingsFile, which will open a web browser and ask you to log in to Windows Azure. Copy the path to the file that downloads, and then run the command Import-AzurePublishSettingsFile <path>, replacing <path> with the path you just copied. The PowerShell window will tell you which subscription is currently active. To select a different subscription use the Get-AzureSubscription to see a list of subscriptions and the Select-AzureSubscription command to pick one.

UPLOAD THE VHD

In the same PowerShell window, run the command:

Add-AzureVhd -Destination <container URL>/<VHD name> -LocalFilePath <path to image VHD>

Replace <container URL> with the URL from the list of containers. <VHD name> can be any name you want for the VHD file in Windows Azure, but make sure you have “.vhd” at the end. Finally, replace <path to image VHD> with the local path of the VHD you created earlier. The command should look something like this:

Add‑AzureVhd ‑Destination http://teststorageacct.blob.core.windows.net/test/test.vhd ‑LocalFilePath “c:\VHDs\test.vhd”

This command will create a hash of the VHD file to ensure it uploads correctly and then begin the upload.

CREATE A NEW WINDOWS AZURE DISK

Once the VHD file is in the storage container, we still need to create an associated disk object that can be attached to VMs. Head back to the Windows Azure Management Portal and click Virtual Machines on the left. Click Disks in the middle of the page and click the Create button at the bottom middle. Give the disk a name and description, and then browse for the VHD you just uploaded. Indicate if the disk has an operating system (OS) installed on it and if so whether the OS is Windows or Linux.

Selecting the OS option will allow you to create a new VM from the disk, but you will not be able to attach it to an existing VM. If you have a disk that has an OS on it that you still want to attach to an existing VM, to do recovery on the system for example, do not select the OS option. You can always delete the disk object and recreate it as an OS disk later.

custom disk 5

Click the checkmark, and Windows Azure will start creating the disk.

CREATING A VIRTUAL MACHINE FROM THE DISK

If you indicated that your disk contains an OS, you can now use it to create a VM. Click the New button at the bottom left, and then under Compute > Virtual Machine, click From Gallery.

custom-disk-5

If everything worked, when you click My Disks you will see your disk.

custom-disk-6

If you don’t see it yet, try reloading the site first. Microsoft’s tutorial walks you through the steps of creating and connecting to the VM from here.

ATTACHING THE DISK TO AN EXISTING VIRTUAL MACHINE

If your disk does not contain an OS, you cannot create a new VM with it, but you can attach it to any other VM in the same subscription. To do so go to the dashboard for the VM you want to attach the disk to by clicking Virtual Machines and then the VM name under Virtual Machine Instances.

custom-disk-7

Then click Attach > Attach disk at the bottom middle. You can also easily attach an empty disk to a VM by selecting the other option here.

custom-disk-8

FINAL THOUGHTS

Windows Azure’s Infrastructure as a Service provides a great way to easily add scalable and resilient capacity to your infrastructure. Microsoft has been steadily improving and adding new features that extend the capabilities of Windows Azure VMs such as autoscaling, endpoint monitoring, and remote PowerShell management. If you are deploying multiple VMs, you can also use Windows Azure custom images to rapidly deploy VMs from your own template.

If you have questions concerning Windows Azure, please contact us or visit our Technology Solutions overview for more information.  For more great Azure tips follow us @CrederaIT and LinkedIn.

Conversation Icon

Contact Us

Ready to achieve your vision? We're here to help.

We'd love to start a conversation. Fill out the form and we'll connect you with the right person.

Searching for a new career?

View job openings