Resize data disk without using deallocate

Rishabh Srivastava 20 Reputation points
2024-03-06T10:16:25.29+00:00

Hi,
I would like to know python sdk code + azurecli command to resize disk without deallocating them.

For more information please refer to the below wiki
https://learn.microsoft.com/en-us/azure/virtual-machines/linux/expand-disks?tabs=ubuntu#expand-without-downtime

Azure Disk Storage
Azure Disk Storage
A high-performance, durable block storage designed to be used with Azure Virtual Machines and Azure VMware Solution.
572 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. TP 75,296 Reputation points
    2024-03-06T12:02:04.7166667+00:00

    Hi,

    To resize managed data disk without deallocating you would use the same technique as deallocating, except you don't deallocate the VM first. Please reference the article you linked to for limitations.

    Below is sample Python code (modified from article) to resize data disk:

    managed_disk = compute_client.disks.get('myResourceGroup', 'myDataDisk')
    managed_disk.disk_size_gb = 256
    
    async_update = self.compute_client.disks.begin_create_or_update(
        'myResourceGroup',
        'myDataDisk',
        managed_disk
    )
    async_update.wait()
    
    

    Below is sample CLI code (from article) to resize data disk:

    az disk update --resource-group myResourceGroup --name myDataDisk --size-gb 256
    

    Please click Accept Answer and upvote if the above was helpful.

    Thanks.

    -TP


  2. Nehruji R 1,666 Reputation points Microsoft Vendor
    2024-03-07T08:25:57.0366667+00:00

    Hello Rishabh Srivastava,

    Greetings! Welcome to Microsoft Q&A forum.

    I understand that you would like to resize the disk without deallocating it using both Python SDK and Azure CLI.Prerequisites:

    1. Ensure you have the latest version of the Azure SDK for Python installed.
    2. Make sure you have the necessary permissions to resize disks in your Azure subscription.

    Steps to Resize a Managed Disk Without Deallocating the VM:

    1. Identify the Disk Resource ID: First, find the resource ID of the disk you want to resize. You can use the following Python code snippet:Python
           from
           
      
    2. Resize the Disk: Use the following Python code to resize the disk:Python
           new_disk_size_gb = 
           
      
    3. Expand the Volume in the Operating System: After resizing the disk, you need to expand the volume within the VM’s operating system to utilize the larger disk space. This step varies depending on the OS (e.g., Windows or Linux).
    4. Restart the VM: Finally, restart the VM to apply the changes. refer - https://learn.microsoft.com/en-us/azure/developer/python/sdk/examples/azure-sdk-samples-managed-disks, https://github.com/MicrosoftDocs/azure-dev-docs/blob/main/articles/python/sdk/examples/azure-sdk-samples-managed-disks.md#resizing-a-managed-disk Customize the above code accordingly to your use case and values.

    Azure CLI Command:

    To resize a data disk attached to an Azure VM without deallocating the VM, follow these steps:

    1. Identify the Disk Resource ID: First, find the resource ID of the disk you want to resize. You can use the following Azure CLI command:
         az vm show -g <resource-group-name> -n <vm-name> --query 
         
      
    2. Resize the Disk: Next, use the following Azure CLI command to resize the disk:
         az disk update --resource-group <resource-group-name> --name <disk-name> --size-gb <new-size>
         
      
      Some alternative way of resizing the disk doc reference - https://www.anoopcnair.com/resize-azure-vm-disk-storage-without-downtime/, https://www.geeksforgeeks.org/microsoft-azure-resizing-virtual-machine-using-powershell-script/.

    Hope this answer helps in detail. Please let us know if you have any further queries. I’m happy to assist you further.

    Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    0 comments No comments

  3. Nehruji R 1,666 Reputation points Microsoft Vendor
    2024-03-07T09:47:55.1566667+00:00

    Hello Rishabh Srivastava,

    Greetings! Welcome to Microsoft Q&A forum.

    I understand that you would like to resize the disk without deallocating it using both Python SDK and Azure CLI.

    Prerequisites:

    1. Ensure you have the latest version of the Azure SDK for Python installed.
    2. Make sure you have the necessary permissions to resize disks in your Azure subscription.

    Steps to Resize a Managed Disk Without Deallocating the VM:

    1. Identify the Disk Resource ID: First, find the resource ID of the disk you want to resize. You can use the following Python code snippet:PythonPythonCopy
            from       
         
      
    2. Resize the Disk: Use the following Python code to resize the disk:PythonRubyCopy
            new_disk_size_gb =      
         
      
    3. Expand the Volume in the Operating System: After resizing the disk, you need to expand the volume within the VM’s operating system to utilize the larger disk space. This step varies depending on the OS (e.g., Windows or Linux).
    4. Restart the VM: Finally, restart the VM to apply the changes. refer - https://learn.microsoft.com/en-us/azure/developer/python/sdk/examples/azure-sdk-samples-managed-disks, https://github.com/MicrosoftDocs/azure-dev-docs/blob/main/articles/python/sdk/examples/azure-sdk-samples-managed-disks.md#resizing-a-managed-disk Customize the above code accordingly to your use case and values.

    Azure CLI Command:

    To resize a data disk attached to an Azure VM without deallocating the VM, follow these steps:

    1. Identify the Disk Resource ID: First, find the resource ID of the disk you want to resize. You can use the following Azure CLI command:YAMLCopy
            az vm show -g <resource-group-name> -n <vm-name> --query 
         
         
      
    2. Resize the Disk: Next, use the following Azure CLI command to resize the disk:DockerfileCopy
            az disk update --resource-group <resource-group-name> --name <disk-name> --size-gb <new-size>
         
         
      
      Some alternative way of resizing the disk doc reference - https://www.anoopcnair.com/resize-azure-vm-disk-storage-without-downtime/, https://www.geeksforgeeks.org/microsoft-azure-resizing-virtual-machine-using-powershell-script/.

    Hope this answer helps in detail. Please let us know if you have any further queries. I’m happy to assist you further.

    Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    0 comments No comments