Symptom:
VM stuck in Reboot Loop. Often due to Failed Windows Updates.
Resolution:
- If Azure PowerShell is not installed, please install it from http://azure.microsoft.com/en-us/downloads/
- Delete the broken VM. All disks will be kept automatically.
- Wait for the disk lease to expire. (About 3 mins)
- Attach the OS disk of the broken VM to a recovery VM located in the same Resource Group and Storage Account.
- Change the Source Type to Existing Blog and browse to the broken VHD.
- Select the broken VHD and continue to attach it to the recovery VM
- Once the disk is attached RDP to the recovery VM and ensure that the attached disk is flagged as ONLINE in the Disk Management console.
- Before doing any changes create a copy of the folder windowssystem32config incase rollback is needed
- On the recovery machine open up regedit
- Select ‘HKEY_USERS’ and select File -> Load Hive
- Browse up to the file windowssystem32configSYSTEM of the attached affected VMs OS Disk. Most likely this will be Drive E: or F:
- When opening it will ask for a name, put ‘BROKENSYSTEM’ and select okay
- Unfold HKEY_USERS and there will be a folder called ‘BROKENSYSTEM’
- In there, make the following changes:
HKEY_USERSBROKENSYSTEMSelectCurrent From 1 to 2
HKEY_USERSBROKENSYSTEMSelectDefault From 1 to 2
HKEY_USERSBROKENSYSTEMSelectFailed From 0 to 1
HKEY_USERSBROKENSYSTEMSelectLastKnownGood From 2 to 3
HKEY_USERSBROKENSYSTEMControlSet002ControlCrashControlAutoreboot From 1 to 0
- Select ‘HKEY_LOCAL_MACHINEBROKENSYSTEM’ then select File -> Unload Hive from the menu
- Remove the now fixed disk from the recovery VM in the Azure Portal
- Wait for the disk lease to expire. (About 3 mins)
- Recreate the original VM using the following script in PowerShell. All this information can be found by selecting the individual resources in the Portal if you are unsure.
Login-AzureRmAccount
Get-AzureRmSubscription
Get-AzureRmSubscription –SubscriptionID “SUBID” | Select-AzureRmSubscription$rgname = “<your RG name>”
$loc = “<your VM location>”
$vmsize = “<your VM size>”
$vmname = “<your VM name>”
$vm = New-AzureRmVMConfig -VMName $vmname -VMSize $vmsize;
$nic = Get-AzureRmNetworkInterface -Name (“YourNICName”) -ResourceGroupName $rgname;
$nicId = $nic.Id;
$vm = Add-AzureRmVMNetworkInterface -VM $vm -Id $nicId;
$osDiskName = “YourDiskOSName”
$osDiskVhdUri = “YourDiskOSUri”
$vm = Set-AzureRmVMOSDisk -VM $vm -VhdUri $osDiskVhdUri -name $osDiskName -CreateOption attach -Windows
New-AzureRmVM -ResourceGroupName $rgname -Location $loc -VM $vm -VerboseHere is an example of what is should look like:# To login to Azure Resource Manager
Login-AzureRmAccount
# To view all subscriptions for your account
Get-AzureRmSubscription
# To select a default subscription for your current session
Get-AzureRmSubscription –SubscriptionID “12345678-1234-123r-5332-522214446c32” | Select-AzureRmSubscription
$rgname = “server2012r2”
$loc = “southcentralus”
$vmsize = “Standard_A1”
$vmname = “server2012r2”
$vm = New-AzureRmVMConfig -VMName $vmname -VMSize $vmsize;
$nic = Get-AzureRmNetworkInterface -Name (“server2012r2577”) -ResourceGroupName $rgname;
$nicId = $nic.Id;
$vm = Add-AzureRmVMNetworkInterface -VM $vm -Id $nicId
$osDiskName = “server2012r2”
$osDiskVhdUri = “https://server2012r23384.blob.core.windows.net/vhds/server20121163546110340.vhd”
$vm = Set-AzureRmVMOSDisk -VM $vm -VhdUri $osDiskVhdUri -name $osDiskName -CreateOption attach -WindowsNew-AzureRmVM -ResourceGroupName $rgname -Location $loc -VM $vm -Verbose
- Run the script and head to the portal. Once the VM is finished being created connect via RDP