I'm trying to stay away from how-to type blog posts, but I think this needs to be posted somewhere... as it has caused me loads of pain over the past 12 hours!
The issue:
- I had an issue where a virtual machines OS drive had became corrupted (no idea why!)... So it was restored from backup as a new virtual machine.
2. The restore worked, which was great. However, due to timings, the latest backup was missed... so there was a whole day of data missing
3. So, how hard would it be to mount the OS disk from the original VM to the new VM? Turns out.. absolute pain in the arse.
4. When I tried to attach the disk, I got the following error:
In order to use it as a data disk, remove the encryption settings and ensure that the virtual machine’s OS disk has the applicable encryption settings define
5. After a google, I couldn't find anything other than a similar issue where people were trying with Terraform.
The Fix
- After some digging and various conversations, it was a matter of changing the disk metadata.
- To resolve, I ran the following PowerShell:
New-AzureRmDiskUpdateConfig -EncryptionSettingsEnabled $false |Update-AzureRmDisk -diskName $osDiskName -ResourceGroupName $rgName
Simply set $osDiskName to the original OS disk and the resource group to which it is a member
3. Mount the disk as a data disk and power on the Vm.
Conclusion
Once done, you can see the disk in disk management and access the data. Don't forget to re-enable back-up and install the various agents!