Extend Microsoft Azure Data Disk & OS Disk
Extend Microsoft Azure Data Disk & OS Disk
To extend Microsoft Azure Data Disk & OS Disk, the Powershell method can be used for both Classic and ARM models. By default, the OS disk will be 30 GB for Virtual Machines, which may not be sufficient as the ore data is started to get saved into the OS drive.
Extend Data Disk using Powershell – Classic Mode
To extend a Data disk in an Azure Virtual Machine in Classic Mode, we need to perform the below steps,
- Open the Windows Powershell ISE and execute the below script
# Authenticate to Azure Account Add-AzureAccount # Select Azure Subscription $subscription = (Get-AzureSubscription).SubscriptionName | Out-GridView ` -Title "Select Azure Subscription" ` -PassThru Select-AzureSubscription -SubscriptionName $subscription -Current # Now select the Azure Storage Account $storageAccount = (Get-AzureStorageAccount).Label | Out-GridView ` -Title "Select Azure Storage Account" ` -PassThru Set-AzureSubscription -SubscriptionName $subscription -CurrentStorageAccountName $storageAccount # Select Azure VM $vm = Get-AzureVM | Out-GridView -Title "Select your virtual machine" ` -PassThru # Select Data Disk to resize $disk = $vm | Get-AzureDataDisk | Out-GridView ` -Title "Select the data disk to resize" -PassThru $datadiskName = $disk.DiskName # Specify new Data Disk size in GB, which should be larger than the current disk size do { $size = Read-Host -Prompt "Specify the new size in GB" } until ( $size -gt $disk.LogicalDiskSizeInGB ) # Stop and Deallocate VM prior to resizing data disk $vm | Stop-AzureVM -Force # Resize Data Disk to Larger Size Update-AzureDisk -Label "$datadiskName" -DiskName "$datadiskName" -ResizedSizeInGB $size # Start your Virtual Machine $vm | Start-AzureVM
Extend Data Disk using powershell – ARM Mode
To extend a Data disk in an Azure Virtual Machine in ARM Mode, we need to perform the below steps,
- Open the Windows Powershell ISE and execute the below script
# Authenticate to Azure Account Login-AzureRmAccount # Select Azure Subscription $subscription = (Get-AzureRmSubscription).SubscriptionName | Out-GridView ` -Title "Select Azure RM Subscription" ` -PassThru Select-AzureRmSubscription -SubscriptionName $subscription -Current $rgName = 'Enter your Resource Group Name' $vmName = 'Enter your VM Name' $vm = Get-AzureRmVM -ResourceGroupName $rgName -Name $vmName Stop-AzureRmVM -ResourceGroupName $rgName -Name $vmName $vm.StorageProfile.DataDisks[0].DiskSizeGB = <Enter your Disk Size in GB> # Example, $vm.StorageProfile.DataDisks[0].DiskSizeGB = 1023 # In the above example, Data Disk is the first one and new size is 1023 GB Update-AzureRmVM -ResourceGroupName $rgName -VM $vm Start-AzureRmVM -ResourceGroupName $rgName -Name $vmName
Extend OS Disk using Powershell – Classic Mode
To extend a OS disk in an Azure Classic Mode Virtual Machine, we need to perform the below steps,
Open the Windows Powershell ISE and execute the below script
# Authenticate to Azure Account Add-AzureAccount # Select Azure Subscription $subscription = (Get-AzureSubscription).SubscriptionName | Out-GridView ` -Title "Select Azure Subscription" ` -PassThru Select-AzureSubscription -SubscriptionName $subscription -Current # Now select the Azure Storage Account $storageAccount = (Get-AzureStorageAccount).Label | Out-GridView ` -Title "Select Azure Storage Account" ` -PassThru Set-AzureSubscription -SubscriptionName $subscription -CurrentStorageAccountName $storageAccount # Get the Azure VM OS Disk Details Get-AzureVM -ServiceName “<Enter your Cloud Service Name>” -Name “<Enter your Virtual Machine Name>” | Get-AzureOSDisk # Select Azure VM $vm = Get-AzureVM | Out-GridView -Title "Select your virtual machine" ` -PassThru # Select Data Disk to resize $disk = $vm | Get-AzureOSDisk | Out-GridView ` -Title "Select the OS disk to resize" -PassThru $osdiskName = $disk.DiskName # Specify new Data Disk size in GB, which should be larger than the current disk size do { $size = Read-Host -Prompt "Specify the new size in GB" } until ( $size -gt $disk.LogicalDiskSizeInGB ) # Stop and Deallocate VM prior to resizing OS disk $vm | Stop-AzureVM -Force # Resize OS Disk to a Larger Size Update-AzureDisk -Label "$osdiskName" -DiskName "$osdiskName" -ResizedSizeInGB $size # Start your Virtual Machine $vm | Start-AzureVM
Extend OS Disk using Powershell – ARM Mode
To extend a OS disk in an Azure ARM mode Virtual Machine, we need to perform the below steps,
Open the Windows Powershell ISE and execute the below script
# Authenticate to Azure Account Login-AzureRmAccount # Select Azure Subscription $subscription = (Get-AzureRmSubscription).SubscriptionName | Out-GridView ` -Title "Select Azure RM Subscription" ` -PassThru Select-AzureRmSubscription -SubscriptionName $subscription -Current $rgName = 'Enter your Resource Group Name' $vmName = 'Enter your VM Name' $vm = Get-AzureRmVM -ResourceGroupName $rgName -Name $vmName Stop-AzureRmVM -ResourceGroupName $rgName -Name $vmName $vm.StorageProfile.OSDisk.DiskSizeGB = <Enter your Disk Size in GB> Update-AzureRmVM -ResourceGroupName $rgName -VM $vm Start-AzureRmVM -ResourceGroupName $rgName -Name $vmName
Extend the File System Volume of Extended Data or OS Disk – Windows
Once the data disk is extended, the next step is to extend the file system volume on that data disk. For Windows based virtual machines, You can do the volume extension from Server Manager -> Tools -> Computer Management -> Disk Management
Step 1. Open the Server Manager Window
Step 2 : Click Tools and then click Computer Management
It will open up a window similar to the below picture. Click the Disk Management menu. It will list all the available volumes.
Select the Volume, that you wish to extend. Right click the volume to open the menu. Click the Extend Volume option.
Click Next button as shown below
Then select the size as shown below. Here, we are using a sample volume to extend. So we are extending by 397 MB. After the size is selected, click “Next“
Now click “Finish” to complete the volume resize.
Now you will see the extended volume under Disk Management.
https://docs.microsoft.com/en-us/azure/virtual-machines/virtual-machines-windows-expand-os-disk