Azure Restore doing an OS Unmanaged Disk Swap

Background

I came across a situation recently that involved restoring an existing Azure VM using unmanaged disks. Keyword unmanaged disks – there is a bunch of info onUnlike my familiar world of VMware, Azure is a different animal. Disks, storage accounts, Nics, VM configurations, NSG (Firewalls), Load balancers, Availability Groups are all objects that connect in a symbiotic environment in order to operate. Changing a link in that environment like a disk takes a delicate dance to ensure things can be restored or replaced in order to operate. Its not as straight forward as simply replacing a VHD and starting up the VM.

I had a heck of a time finding the steps I needed to replace the bad disk with the restored disk. Trying a simple restore of the VHD and putting it in the blob container didk not work. What I found was that you actually need to link the disk using powershell.

Here’s what I did to get things back up and running.

Pre-requisites
i) Install Azure Powershell module via powershell? Type in
? ? ? Install-Module -Name AzureRM -AllowClobber

ii) Install Azure Storage explorer and sign in https://azure.microsoft.com/en-us/features/storage-explorer/

 

Procedure

  1. Restore the VHD disk with the restore point you desired by creating a new VHD disk with the restore point
    1. (Do NOT try to restore on the existing disk – it only works with managed disks)
    2. Choose a storage account (the same one is fine because it creates a new blob container)
  2. Wait for a long time (exaggerated) for the restore
  3. Go in storage explorer and copy the restored disk URI in the blob container of the VM you will need this later.
  4. Run this handy script (copied from this guys’ handy article-?https://marckean.com/2017/11/11/change-azure-arm-vm-os-disk/)

#region Logon to Azure

Login-AzureRmAccount

$subscription = Get-AzureRmSubscription | Out-GridView -PassThru

Select-AzureRmSubscription -SubscriptionId $subscription.Id

#endregion

# Variables for YOu to fill in

$ResourceGroup = ‘Resource_group_name’ # resource group name to contain the new NIC

$VMname = ‘your_vm_name’ # name of the VM you want to swap out the OS disk

#Get the VM config to a variable

$VM = Get-AzureRmVM -Name $VMname -ResourceGroupName $ResourceGroup

#Stop and deallocate the VM

Stop-AzureRmVM -Name $VM.Name -ResourceGroupName $VM.ResourceGroupName -Force

#swap out the OS disk using the VM variable

$VM.StorageProfile.OsDisk.Vhd.Uri = ‘https://auw1os01.blob.core.windows.net/ehwssostsp01-a4d28159aa2a4f01b3d64f2d18d59063/ehwssostsp01-osdisk-20181102-202000.vhd’

#Update the VM configuration

Update-AzureRmVM -VM $VM -ResourceGroupName $ResourceGroup

? ? ? ? 5.? Start up your VM.

6. Verify everything looks good.

 

Reference:

Many thanks to this article.?https://marckean.com/2017/11/11/change-azure-arm-vm-os-disk/

For managed OS disk swaps you can find the following Azure article?https://azure.microsoft.com/en-us/blog/os-disk-swap-managed-disks/