Munchkin
Munchkin

Reputation: 4946

Clone VM with new CloudService, VNet and Storage Account

I try to clone an existing VM. Requirements:

So at first I captured my existing VM. Now here are my 4 tries which didn't work:

  1. Create via preview portal: -> not possible because you can't create a VM from an image here.
  2. Create via classic portal: -> I can't select a new storage account so the .vhd of the new VM will be located in the existing storage account
  3. Using this script to copy the existing VM. -> I got this error: New-AzureVM : ConflictError: A disk with name xxxxx is currently in use by virtual machine xxx running within hosted service xxx, deployment xxx. Yeah, of course the disk is in use by a VM; I thought this script deals with this fact and copies both VM and vhd?!
  4. Create a new (empty) storage account and copy the existing .vhd & .status blob files from the old into the new storage account (I used this tutorial). Both files were copied successfully. -> Now I wanted to create a new VM "from existing VHD" (via classic portal) but the new (copied) VHD doesn't appear here.

So I'm out of ideas how to clone a VM with my requirements. Hope you can help.

Upvotes: 0

Views: 311

Answers (1)

Aatif Akhter
Aatif Akhter

Reputation: 2206

If you know Azure PS this can be done in these steps.

Step 1. Move all the vhds to your newstorge account which you have already done. great !

Step 2. convert the vhds to disk using Azure PS-

Add-AzureDisk -DiskName "YourVHDName" -MediaLocation "https://NewStorageAccountName.blob.core.windows.net/vhds/YourVHDName.vhd" -os "Windows" (for os disk )

Add-AzureDisk -DiskName "YourVHDName" 
-MediaLocation "https://NewStorageAccountName.blob.core.windows.net/vhds/YourVHDName.vhd" 

Step 3. Most Important spin vm using OS disk-

Set-AzureSubscription -SubscriptionId "YourSubscriptionId"-CurrentStorageAccountName "NewStorageAccount"

$vm=New-AzureVMConfig -DiskName "YourVHDName" -InstanceSize "YourInstanceSize" -Name "YourVMName" 

New-AzureVM -Location "YourLocation" -ServiceName "YourNewService" -VNetName "YourNewvNet" -VM $vm -verbose
  1. Step 3 will spin vm for you. Now simply attach the disk to vm which you have already created in step 2

Upvotes: 1

Related Questions