Azure hard-codes disk size and it cannot be changed during deployment. Resizing root disk on Azure is often a required task. Here is how a root disk can be resized. I learned this the hard way.

Once an instance is launched, shut it down. I use Azure powershell (since azure-cli doesn’t support resizing disk at the time of writing).

It’s a good idea to first look at the partition table before we do anything. This is from a freshly deployed Oracle Linux 6.4. Note that the last 2014 sectors are not used:

OK so we’re ready to shutdown the VM and expand the disk. Here, I’m increasing it to 60G. First, setup your azure power shell if this is the first time you run it

Then query the disk name, stop (deallocate) the VM and resize the azure disk. Start the VM up after.

When the VM comes back, we can proceed to the usual partition table editing and filesystem resizing. But here is the fun part. Do not use all the space on the disk. I believe the very last 2014 sectors are used by Azure HyperV. If you include those sectors in your partition, your VM will no longer boot. It may not happen immediately, but it happened to me 5 times when there are some substantial write activities.

Here, I use fdisk to delete the 3rd partition and recreate it. Noticed that I deducted 256 sectors when I put in the ending sector of partition 3. I want to play safe so I used a bit more than 34s. It’s only 128KB, you’re not going to miss it.

When it’s done, gdisk no longer complains about partition table problem.

Proceed to resizing your filesystem online, and when it’s done, you’ll get a 60G root filesystem.

Remember to reboot the VM one more time. If it’s going to have problem, better happens sooner than later.

One Thought to “Resize root disk on Azure VM”

  1. Spot on with this write-up, I honestly believe this site needs a great deal more attention.
    I’ll probably be back again to read through
    more, thanks for the info!

Leave a Comment