Resizing Data Disks in the Cloud on Microsoft Azure with Windows PowerShell
Join the DZone community and get the full member experience.
Join For FreeResizing existing Azure VM data disks just got a whole lot easier with the introduction of an enhanced Update-AzureDisk PowerShell cmdlet in the latest version of the Azure PowerShell module.
In this article, I’ll step through the process of using this new cmdlet to increase the size of an existing data disk on an Azure virtual machine.
Getting started …
To follow along with the steps in this article, you’ll need an active Azure subscription and the latest version of the Azure PowerShell module, which is version 0.8.15.1 as of this article’s date.
- Sign-up for a FREE Azure trial subscription, or Activate your Azure MSDN benefits
- Download and install the latest Azure PowerShell Module
In order to resize an existing VM data disk, you’ll also need to have at least one VM provisioned with a data disk attached.
Resize Azure Data Disks via Azure PowerShell Script
Below, I’ve included a sample Azure PowerShell snippet that you can incorporate into your own script for increasing the size of existing Azure VM data disks.
# 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 # Select 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 a VM ..." ` -PassThru # Select Data Disk to resize $disk = $vm ` | Get-AzureDataDisk ` | Out-GridView ` -Title "Select a data disk to resize" ` -PassThru $diskName = $disk.DiskName # Specify new Data Disk size – must be larger than current size do { $size = Read-Host ` -Prompt "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 "$diskName" ` -DiskName "$diskName" ` -ResizedSizeInGB $size # Start VM $vm | Start-AzureVM
Extending the Data Volume
After updating the data disk to a larger size, you’ll need to extend the file system volume on that data disk to be able to access the additional space. You can easily perform this task using Server Manager from within a Remote Desktop connection to the Azure VM.
Published at DZone with permission of Keith Mayer, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Trending
-
Grow Your Skills With Low-Code Automation Tools
-
Hiding Data in Cassandra
-
Getting Started With the YugabyteDB Managed REST API
-
Microservices With Apache Camel and Quarkus (Part 3)
Comments