Azure VM change OS Disk
Solution 1
To create a new VM, using the existing disk you should be able to do so with the following PowerShell (this is simplified, I haven't added any NICS etc.).
$vm = New-AzureRMVMConfig -VMName $vmName -VMSize $vmSize
$osDiskUri = "https://nameofyourstorageaccount.blob.core.windows.net/vhds/nameofyourvhd.vhd"
$vm = Set-AzureRMVMOSDisk -VM $vm -Name $osDiskName -VhdUri $osDiskUri -CreateOption attach -Windows
New-AzureRMVM -ResourceGroupName $rgName -Location $location -VM $vm
Solution 2
In case if you need non-power-shell way out of this then following worked for me.
I had accidentally deleted one of the SQL Server VM from my SharePoint 2013 farm using the new Azure Portal. The disk VHD file was still intact on the blob storage of my storage account as usual.
Download CloudXplorer. Launch > Manage Account> Azure Blob Storage Account. Enter storage account name and the key (you'll get it from azure portal). You see all VHD files, etc. Locate the one that matches name of the VM you deleted. Pick the most recent one that you want to restore to. Note down its full name (*.vhd). Then, right click on that and select break lease.
Go back to Azure Portal. Delete the NIC and disassociate the Public Static IP. Create a new VM with exactly same configuration as before. When it is ready, it will provision new NIC and new OS Disk. Stop the VM and go to Disks section in the properties. Note down the full url of the VHD file in use. Go back to CloudXplorer and hit refresh. Search for the new VHD that was created and copy its name. Delete it. Then rename the original one with the name you copied.
Go back to Azure Portal. Associate the public static IP with newly created NIC for the new VM. (In my case internal IP's were preserved because no other VMs were being provisioned at that moment.) Then, start the VM. That's it.
No impact on the SharePoint farm.
Related videos on Youtube
Berndinox
Updated on September 18, 2022Comments
-
Berndinox over 1 year
I've create an Azure VM in RM and have deleted the VM and Components expect the OSDisk in an Premium Storage Account (Blobs). Now i wouldd like to create an new VM and attach the OS Disk to the new VM.
I've tried to use the Set-AzureRmVmOsDisk, to an existing VM. That does not work. I also tried creating a new VM and modify the OSDisk. But there is the Error:
New-AzureRmVM : Changing property 'osDisk.name' is not allowed.
Any idea on how to create an new VM and assign an OS .vhd from an old VM as new System Disk`?
EDIT: I've tried the following:
$VM = Get-AzureRmVM -Name "VM01" -ResourceGroupName "TestResource1" Set-AzureRmVMOSDisk -VM $VM -Name "**VM123456**.vhd" -VhdUri "https://vm01disk.blob.core.windows .net/vhds/**VM123456**.vhd" -CreateOption Attach
The output show:
"osDisk": { "osType": null, "encryptionSettings": null, "name": "VM123456.vhd", "vhd": { "uri": "https://vm01disk.blob.core.windows.net/vhds/**VM123456**.vhd" },
After running the command:
Get-AzureRmVM -Name "VM01" -ResourceGroupName "TestResource1"
again, i can see:
"osDisk": { "osType": "Windows", "encryptionSettings": null, "name": "VM01", "vhd": { "uri": "https://vm01disk.blob.core.windows.net/vhds/**VMoldID**.vhd" },
There was no Error, and the prompt from the command indicates the changes have been done. But when calling the infos from the VM again, there is still the old vhd
-
Sam Cogan about 8 yearsHe is trying to create a resource manager (v2) VM, you cannot do this from the old portal.
-
Berndinox about 8 yearsThanks for your answer, in the new portal i can just see my storage account, and inside the blobs, there are my .vhds. I just have the option to download them. Can you provide me with a link to "Disks" inside the Manager?
-
Berndinox about 8 yearsThanks, that did the trick! I've just added an NetworkProfile (azure.microsoft.com/en-us/documentation/articles/…) - BR
-
user3546411 about 7 yearsUsing cloud explorer to break the lease is new magic for me. I've always built templates which attach an exiting disk. The above is faster, more flexible, and less work. Genius! Why MSFT doesn't allow this in the portal is BEYOND comprehension.
-
dsutherland over 6 yearsI actually didn't need to do anything with the nics for this to work. Nice call.