Compartilhar via


Uploading a custom operating system to Azure Virtual Machines

Azure virtual machines comes with a massive gallery of virtual machine images, so you can pick your OS from a variety of options, from Ubuntu to Windows Server 2008 R2. In some situations, you might want to upload your own virtual machine into Azure. For example, if you have a pre-existing server that has a complex configuration in place, it might be easier to just upload the VHD as-is rather than re-create everything on a new VM. For such a situation, Azure allows you to upload your own VHD file, and use it as the basis for a virtual machine. Here’s a guide for doing this.

To upload your custom VHD, you’ll need to use a special upload tool called CSUPLOAD. This ships with the Azure SDK, which you’ll need to download and install. The SDK ties into Visual Studio, so you need to have that installed as well. The upload tool is a command-line tool, so you’ll also need to configure it to authenticate to Azure using a self-signed certificate. Once the setup is ready, you upload your file, and use the Azure wizard to create a VM from it. Here are the detailed steps:

Step 1 – prepare Azure for your VHD

1. Login to your Azure account via https://manage.windowsazure.com/

2. Click on Storage

3. Create a new storage item (for example, “prod”)

4. Open it to retrieve the blob URL (prod.blob.core.windows.net in the screenshot below):

clip_image002

5. Go to Containers to create a container for the VHD (for example, “demo”)

clip_image004

Step 2 – prepare your machine for the upload

1. Install the Azure SDK from https://www.windowsazure.com/en-us/downloads/ (If you’re using Visual Studio 2012, get .NET SDK for VS2012)

Step 3 – configure authentication for the upload procedure

1. Open an Azure command prompt (search start menu for Windows Azure SDK environment) as an Administrator

clip_image006

2. In the command prompt, run the makecert command to generate a self-signed certificate:

makecert -sky exchange -r -n "CN= <Your Cert Name> " -pe -a sha1 -len 2048 -ss My " <Your Cert Name> .cer"

*** The cert name is free choice, but make it descriptive. For example:

clip_image008

This certificate will be used by the Visual Studio uploader to authenticate to Azure so that you can upload your image.

3. Open MMC and add the cert snap in for My User

4. Open the Personal store and find the certificate you created

5. Right click on the certificate and EXPORT it

6. Make sure you export without the private key

7. Go to the Azure management site and go to Settings

8. Upload the certificate you exported in step 5 above

9. From the page, retrieve the subscription ID and Cert Thumbprint (you’d probably want to save it to some local text file or in OneNote)

clip_image010

10. On the VS CMD you used earlier, run this command to setup the connection string:

csupload Set-Connection "SubscriptionID= <Your subscription ID> ; CertificateThumbprint= <Your cert thumb> ; ServiceManagementEndpoint=https://management.core.windows.net"

*** The Subscription ID and thumbprint is your personal one. The URL is fixed. For example:

csupload Set-Connection "SubscriptionID=301849e3-dc98-495d22ab235-bae9-35bd0; CertificateThumbprint=E793515CC9E3063749522017B7DF9E4BA1C65D02; ServiceManagementEndpoint=https://management.core.windows.net"

clip_image012

Step 4 – upload the VHD

1. In the VS CMD that you used before, run the upload command, specifying the blob URL you got in step 1, the target container you created then, and the target file name. You need to also specify the source of the VHD:

csupload Add-PersistentVMImage -Destination "<Blog URL>/<Target container>/<Target File>.VHD" -Label <My Label> -LiteralPath "<VHD source file path>" -OS Windows

For example:

csupload Add-PersistentVMImage -Destination "https://prod.blob.core.windows.net/MyVHDFolder/Build1.VHD" -Label buildone -LiteralPath "F:\MyVHDs\BuildFile.vhd" -OS Windows

clip_image014

Step 5 – create a VM from the VHD

1. In your browser, go to your Azure account, and click on VIRTUAL MACHINES.

2. Click CREATE A VIRTUAL MACHINE

clip_image016

3. Select FROM GALLERY

clip_image018

4. Click MY IMAGES and Select the image you uploaded

clip_image020

5. Complete the wizard with the rest of the details (VM Name, size, username, password etc)

6. Start your VM and start using it!