Condividi tramite


Resizing Azure VM OS or Data Disk

Are you running out of space on the OS or data disk of your Azure VM? Here is a simple way to resize the OS or the data disk. Resizing of the disk is done using Azure PowerShell. If you don’t have Azure PowerShell on your local machine, then you can follow the documentation to install Azure PowerShell in your local machine and connect to your Azure Subscription.

Note: I have tested this for VM's running Windows OS only but not Linux. Also keep in mind that once you run the command to resize the disk it is irreversible. You will NOT be able to shrink the disk. In addition, this applies only to V1 VM's created using Azure Service Manager (ASM). If you like to resize disks for Azure Resource Manager (ARM), see my blog @ Resize Azure Resource Manager (ARM) VM OS & Data disk using Azure Portal

Few things to ensure before performing shutdown/de-allocation of the VM:

  • Make sure you don’t have any data in the Temporary D-Drive in the VM as the data will be lost since it’s a non-persistent drive.
  • You will lose the VIP (Public IP) if this is the only VM in the cloud service. If you need to preserve the VIP, then you can either reserve the VIP or add a test VM in the same cloud service before shutting down the VM that you would like to resize the disks.
  • I highly recommend that you take back up copies of the disk prior to executing any command to resize the disk incase something goes wrong.

 

Resizing OS disk:  

  1. Shutdown (de-allocate) the VM from the Azure portal. Check VM's dashboard to make sure it says Deallocated (See screenshots below)

On the classic portal:                                On the new portal:

 

 

  1. Once the VM is completely de-allocated, then launch Azure PowerShell and connect to your Azure subscription.

 

  1. Then, you will need to collect the OS disk info that you want to resize. Use the command below to output the OS disk details.

Get-AzureVM -ServiceName "<Cloud Service Name>" -Name "<VM Name>" | Get-AzureOSDisk

For example:

Get-AzureVM -ServiceName MnDemoVM2 -Name "MnDemoVM2" | Get-AzureOSDisk

 

  1. If you want to see the current size of your disk, you can either connect to your VM and check or you can check from the portal. To check in the portal, go to the dashboard of the VM and take a note of the VHD path from the disk section in the dashboard (See screenshot below). Then, go to the storage account of that VM and navigate to container where that VHD is located. You will see the size of the disk in the last column of that table.

VHDs Path:

Before Resize:

 

 

  1. Next, run the below command with the OS disk name you have acquired from step-3 to resize the disk.

Update-AzureDisk -DiskName "<OS Disk Name>" -Label Resized -ResizedSizeInGB 400

Note: Azure allows you to have a OS or Data disk up to 1TB (1023 GB) for each disk.

For example:

Update-AzureDisk -DiskName "MNDemoVM2-MNDemoVM2-0-201510092258210053" -Label Resized -ResizedSizeInGB 400

 

 

  1. Now, go back to the same container where the VHD is and you can see the size of the VHD has changed to 400 GB.

 

  1. Once you verify that the disk has been resized, start the VM from the portal and connect to the VM.

 

  1. After you login to the VM, go to Disk Management. You will notice that the disk size has changed to 400 GB now. Right-click on the volume and select 'Extend Volume'. Follow the on-screen steps to extend the volume.

 

 After Extending the volume:

 

 

*********************************************************************************************************************************************************************

Resizing Data disk:

 

  1. The process to resize the data disk is same except the command you run in Azure PowerShell is slightly different.

 

  1. Run the below command to collect the data disk info to resize.

Get-AzureVM -ServiceName "<Cloud Service Name>" -Name "<VM Name>"  | Get-AzureDataDisk

For example:

Get-AzureVM -ServiceName MnDemoVM2 -Name "MnDemoVM2" | Get-AzureDataDisk

  

  1. Check the size of the data disk before resizing.

Before Resize:

 

 

  1. Next, run the below command with the data disk name you have acquired from step-3 to resize the disk.

Update-AzureDisk -DiskName "<Data Disk Name>" -Label ResizeDataDisk -ResizedSizeInGB 500

Note: Azure allows you to have a OS or Data disk up to 1TB (1023 GB)  for each disk.

For example:

Update-AzureDisk -DiskName MNDemoVM2-MNDemoVM2-0-201511032306210081 -Label ResizeDataDisk -ResizedSizeInGB 500

  

  1. Now, go back to the same container where the VHD is and you can see the size of the VHD has changed to 500 GB.

 

  1. Once you verify that the disk has been resized, start the VM from the portal and connect to the VM.

 

  1. After you login to the VM, go to Disk Management. You will notice that the disk size has changed to 500 GB now. Right-click on the volume and select 'Extend Volume'. Follow the on-screen steps to extend the volume.

 

I hope this post helped you resolve your OS or Data disk resizing issue. Please feel free to comment if you have any additional questions.

 

DISCLAIMER: The above blog posting is provided "AS IS" with no warranties and confers no rights.

Comments

  • Anonymous
    December 21, 2015
    Can this be done with a resource manager VM? I don't see any Get-AzureRMOSDisk cmdlets or anything like that avaiable.

  • Anonymous
    February 01, 2016
    Hi Nicolai, there is no option to resize OS or data disk for VM's created using ARM yet.

  • Anonymous
    February 04, 2016
    To resize an ARM vm OS disk with powershell (commandlet options not visible), not sure if it's supported but it works on windows RM VMs. It's very difficult working with the half baked IaaS V2 products. Also note the the azure windows server 2012R2 image from teh market place places the system reserved partition after the OS install - so even after you extenrd the disk, you can't extened C: due to the non contiguous free space. This is more painful than it should be at every turn - so we're likely going to look elsewhere for our cloud platform.   #note this powers down and deallocates the VM as it can't be done live Login-AzureRmAccount $VMname = "VMnameHere" $rsg = "resourcegroupnameHere" $VM = Get-AzureRmVM -Name $VMname -ResourceGroupName $rsg Stop-AzureRmVM -Name $vmname -ResourceGroupName $rsg -Force

set OS disk to 200GB

$vm.StorageProfile.OsDisk.DiskSizeGB = 200 Update-AzureRmVM -VM $VM -ResourceGroupName $rsg #to resize data disk also Set-AzureRmVMDataDisk -Name diskname.vhd -DiskSizeInGB 1023 -Caching None -VM $VM Update-AzureRmVM -VM $VM -ResourceGroupName $rsg

* **Anonymous**  
September 23, 2016  
Azure RM supports for resize of data disk. If yes share us the REST API details for the same.  
	* **Anonymous**  
	September 27, 2016  
	Vijay, For ARM VM's, you can resize OS/data disk within the new portal. Quickly blogged about it here, https://blogs.msdn.microsoft.com/madan/2016/09/28/resize-azure-resource-manager-arm-vm-os-data-disk-using-azure-portal/  
  • Anonymous
    July 19, 2016
    Very useful .. thanks
    • Anonymous
      November 10, 2016
      Thank you Radu for the feedback. :)
  • Anonymous
    March 09, 2017
    Great ! Thk's !
  • Anonymous
    March 10, 2017
    Thank you for this. I've been struggling to find a write up of how to expand an Ubuntu drive in Azure using PowerShell. Following steps 1 - 8 solved this for me.
  • Anonymous
    April 07, 2017
    Does this work for encrypted Windows VM's ?
  • Anonymous
    April 01, 2019
    Thank you for the Info. But this is outdated. In Azure portal you can easily change the disc size ;)
    • Anonymous
      April 16, 2019
      Hi Arash, From the Azure Portal, you can only change the OS/Data disk size for the ARM VMs. For Classic VMs, you cannot do it using the Azure Portal and thus need to follow the steps documented above in this blog.