azureazure-virtual-machineazure-cliazure-disk

Azure CLI - How to update cache setting of a live managed data disk attached to an Azure VM


Need some help figuring out the Azure CLI command and parameters to update cache setting of a live managed data disk attached to an Azure VM.

A managed data disk is created and attached to an Azure VM outside of my control. By default, Host caching is set to Read-Only. For some performance reasons, I would like to set Host caching to None for the attached data disk.

What did I try?

  1. Tried to use below command
az vm update --subscription my-subscription --name my-vm-name --resource-group my-rgroup-name --disk-caching os=ReadWrite

This command updates the OS Disks Host cache setting. However, could not update managed disks setting. I tried different keys like managed, data-disks, attached, etc... instead of os in os=ReadWrite; Nothing worked, command throws ValueError

ValueError: invalid literal for int() with base 10: 'data-disks'
  1. Explored another command - az disk update. However, it does not have option to update managed disk cache setting.

  2. Tried to detach and re-attach the managed disk with --caching set to None. It works. However, this is not permitted in my case.

az vm disk detach --subscription my-subscription -g my-rgroup-name --vm-name my-vm-name --name managed-disk-name

az vm disk attach --subscription my-subscription -g my-rgroup-name --vm-name my-vm-name --name managed-disk-name --caching none

Need this for automation. So changing this setting from Azure portal UI is not an option.

Suggestions are much appreciated.


Solution

  • Without detaching the disk from virtual Machine using the below cmdlet to change the managed disk caching from ReadWrite\ReadOnly to None.

    We have tested this cmdlet in our environment by creating a VirtualMachine & attached a Data disk to it and it is working fine.

    Here is the Cmdlet:

    az vm update --resource-group <resource-group-name> --name <vmName> --disk-caching os=ReadWrite 0(LunNumberOfTheDisk)=None
    

    Here is the sample output screenshot for reference :

    1. Below screenshot show the current state of disk caching before executing the above cmdlet.

    enter image description here

    1. In the below screenshot , you can see we have executed the cmdlet without stopping or detaching the disk from the virtual machine and the operation got succeeded without any interruption.

    enter image description here