Step by Step: how to resize a Linux VM OS disk in Azure (ARM)

The default OS disk size for most Linux distros in Azure is 30GB. While Linux makes it easy to add other disks as mount points, you may wish to increase the size of the OS disk using the steps in this article.

Here’s what you need to do. I used a CentOS 6.8 Linux VM from the Azure Marketplace in this example. Default filesystem is ext4. With CentOS/RHEL 7.x, the default file system is XFS. On Ubuntu it is not necessary to do steps 2-11 as it automatically will resize the disk on boot.

Note: Before proceeding it’s highly recommended that you backup your Azure VM first. You can do this using Azure Backup or use AzCopy to make a copy of your VHD.

1) Resize the OS disk using these PowerShell cmdlets or the Azure CLI. The VM needs to be in stopped (deallocated) state to run these commands


$rg = “YourResourceGroupName”
$vmName = “YourVMName”
$vm = Get-AzureRmVM -ResourceGroupName $rg -Name $vmName
$vm.StorageProfile[0].OSDisk[0].DiskSizeGB = 127  # change the size as required
Update-AzureRmVM –ResourceGroupName $rg -VM $vm


Azure CLI:

az vm update --resource-group YourResourceGroupName --name YourVMName --set storageProfile.osDisk.diskSizeGB=1024


2) Start your Linux VM. Login to your Azure VM using SSH:

As you can see the OS disk is 30GB.

3) Run this command: sudo fdisk /dev/sda

4) Type “u” to change the units to sectors.

5) Type “p” to list the current partition details. Note the starting sector (e.g. 2048).

6) Once you are in fdisk, delete the partition (note: you aren’t deleting the data, just altering the partition table). Type “d” and then select the partition (if required as it will choose partition 1 if it’s the only partition).

7) Create a new partition with “n”. Type p to create a primary partition. Type 1 to create the first partition (or another partition number, if required). Use the same starting sector from step 5 and use the desired end sector or accept the default end sector to use the entire disk.

8) Type “a” and select partition 1 to mark the boot partition as active. Type “p” to to ensure all settings are correct:


9) Write the partition with “w”. You will get a warning that says: WARNING: Re-reading the partition table failed with error 16: Device or resource busy. This is normal.

10) Reboot using “sudo reboot”

11) Once the VM is up and running, login to your Azure VM using SSH and type “sudo resize2fs /dev/sdaX” to resize the filesystem for CentOS/RHEL 6.x (where X is the partition number you created in step 7. In CentOS/RHEL 7.x the command is “xfs_growfs -d /dev/sdaX”. This may take some time to complete.

12) Verify the new size with df -h



Now go and enjoy your new bigger OS disk!

Updated 1/3/2017: Thanks to Terry Charles for noting that step 8 to mark the boot partition was inadvertently omitted. Also, thanks to rhelguy and Sherif Adel for the correct resize command for CentOS/RHEL 7.x.

Comments (7)

  1. Niklas Lundgren says:

    Great article! With CentOS >7 the filesystem used is XFS by default so the commands used to resize the disk is a little bit different.

  2. rhelguy says:

    Use 'xfs_growfs -d /dev/sdaX' instead of 'resize2fs /dev/sdaX' for RHEL 7.

  3. Jeff says:

    It is probably worth mentioning that some Linux distributions need to boot flag setting (by using the a command and partition number) before you write the configuration back and reboot

  4. Sherif Adel says:

    If you have and "XFS" file system, like by default in CentOS, you should use " xfs_growfs" instead of "resize2fs" command.
    I think this would be helpful to update in the document 🙂

  5. cegfb says:

    Great!!!, thank you very much, plese, but to Centos 7 ???

  6. Bob Rapelje says:

    This article is helpful, but what a pain for large customers to do this on all their virtual machines.

    It would be nice if Microsoft allowed users to initially provision a virtual machine with the disk size of the customer's choosing. (like AWS and Google)

  7. ahom kumar says:

    Followed the step in rhel 7. after rebooting not able to ssh into the server.

Skip to main content