Unable to mount azure OS disk as data disk

I had a nightmare after a VM restore with mounting OS disks as a data disk. Fixed the 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"

Unable to mount azure OS disk as data disk

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:

  1. 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

  1. After some digging and various conversations, it was a matter of changing the disk metadata.
  2. 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!

Ready to build yours?

I'm building a programme for senior technologists who are ready to go independent. Business foundations, personal brand, tech-enabled delivery, and the life design that makes it all worthwhile. If that's you, get on the list.

You're on the list. Check your inbox to confirm.

Something went wrong. Please try again.

No spam. Just honest writing about building independence.