Several months ago I have written two functions
New-AzVmDisk that are intended to retrieve disk info and create new data disks for Azure VM(s).
Today to close the topic, we will talk about how to increase existing OS and Data disks. It will be Expand-AzVmDisk function.
Expand-AzVmDiskfunction from my Azure Automation Az-Module can increase as well as
- The function has only two parameters
-SizeGBand both are mandatory.
For more convenience it supports pipeline input from the
Get-AzVmDiskfunction to get disk object(s).
Select-AzResourceGroup | Select-AzObject VM | Get-AzVmDisk | Expand-AzVmDisk -SizeGB 150
- In all examples in this article I will use two auxiliary functions
Select-AzObject, described in this article in the
Increase Data Disks
- Let go straight to examples. Select a VM and check its current disk info and power state.
Select-AzResourceGroup | Select-AzObject VM | Get-AzVmDisk Select-AzResourceGroup | Select-AzObject VM | Get-AzVmPowerState
- As we can see, this is powered on VM with OSDisk only. Let add to it a single 10GB Data disk and try to increase it to 20GB.
Select-AzResourceGroup | Select-AzObject VM | New-AzVmDisk OSDisk 10 Select-AzResourceGroup | Select-AzObject VM | Get-AzVmDisk DataDisk | Expand-AzVmDisk 20
- Note that disk increase operation is irreversible (this mean you will not be able to decrease a disk anymore), therefore the function requires to confirm your intension. But if you’re sure what you’re doing, the
-Confirmparameter is for you.
Select-AzResourceGroup | Select-AzObject VM | Get-AzVmDisk DataDisk | Expand-AzVmDisk 25 -Confirm:$false
- The same way we can increase the OS disk too.
Select-AzResourceGroup | Select-AzObject VM | Get-AzVmDisk OSDisk | Expand-AzVmDisk 150
- The only difference in the case of the OSDisk, if VM is powered on, the
Expand-AzVmDiskwill stop (deallocate) it first, then increase the disk and after that power VM on.
Select-AzResourceGroup | Select-AzObject VM | Get-AzVmPowerState
- There are maximum disk size restrictions. Currently and this is recently changes, a
OSDiskmaximum size is 2TB or 2048GB and
DataDiskis restricted to 4TB (4095GB).
OSDisksize would be 127GB, but a disk size is not exposed via Azure API and you will see it equal to
0(zero) in the
Expand-AzVmDiskfunctions and blank in the Azure portal.
The real OS disk size can be seen in a VM guest OS only! Use the
Disk Managementapplet for Windows guests and
dffor Linux to view it and … of course, extend your partition to utilize the just added disk space .
For more details about the function, please take a look at the content based help and examples.
Get-Command -Module Az-Module -Noun azvmdisk Get-Help Expand-AzVmDisk -Full Get-Help Expand-AzVmDisk -Examples Get-Help Expand-AzVmDisk -Parameter Disk