Resizing an Azure Debian OS Disk – 2018

Yes yes, its been a while.  Frankly I forgot I had a blog.  I am mainly posting this for my own later self googling, because I keep forgetting things in my old age, but I hope it helps you too!

For some time now my company has been providing Azure hosting services, and more and more those servers that are running on Azure are using the Debian OS.  One of the issues with this is that by default the Azure system will set the OS disk to a 30GB Partition even if you build the VM with more.

If you get resizing wrong on the OS disk, the only option really is a restore from backup, which is a pain in the ass to say the least.  What makes this process even more sucky is that Microsoft have about 20 articles that all contradict themselves and are not clear for Debian Azure Instances which is what this post is for if you googled “How to expand Azure Debian OS disk”.  You might even search for “Expand Debian Managed OS Disk” like I did a ton of times, so that is there for the google bots….

So, here are the steps, with a MAJOR gotcha that isn’t mentioned anywhere in the online documentation I found

Backup your VM

Yes, its a pain especially if you just built the machine, but do yourself a favour and backup your VM using Azure Backup before you do any of this stuff.  Unless you are willing to risk the VM and start again.  Also, as noted by one of our team, just CLICKING backup doesn’t mean its actually run.  Make sure it runs (you have to click “create backup”) 🙂

You do not need to expand drives using CLI or Commands.  You can do it in the Azure GUI easily.

The online documentation you will find will push you to using Azure CLI 1.0 or CLI 2.0.  Ignore it.  Simply do this:

Shutdown (Deallocate) your VM in the GUI.

 

Open the Disks menu item and then change your disk size

 

 

Start Backup your machine and then connect and run the following commands.  

Do this slowly and check each step.

Note the first step!  

(If you miss this step, you will NOT see all the SDA partition – this is the first undocumented gotcha)

 

sudo su

(type your password)

 

sudo fdisk /dev/sda

d (Delete Partition) – Do this.  Dont worry, until you write changes at the end you are ok.

F (Show all space) – When you run this you should see ALL the space you set the drive to.  If you don’t you probably forgot the sudo su)

p (Will show you the free space)

 

The next part creates a new partition.  I repeat, you need to know above that ALL the space you created was available.

n (Will create new partition)

(primary Partition, or just press enter to accept it as default)

1 (Partition 1, or just press enter to accept is as default)

For the next part you should go with the defaults they show you on the screen (see GIF below).  It should automatically select the first and last sectors of the drive.  If you do not see the full amount, then you are not running as sudo su.

IMPORTANT:

DO NOT REMOVE SIGNATURE when asked.  Select NO

ALSO IMPORTANT:

(this makes the partition bootable / active).

 

If you are happy you did all of the above, then you can:

(Write the changes to the disk)

reboot (reboot the VM).

 

GIF below of me doing all that, and probably some other things….

 

 

But wait, there is more….   after the reboot you have to expand.  To do this:

sudo su (still important)

type password

resize2fs /dev/sda1

then check your disk…. it should be the right size

df -h

 

Another GIF of me doing things….

 

Thats it, I hope it helps!

 

Nick

 

 

 

 

  2 Replies to “Resizing an Azure Debian OS Disk – 2018”

  1. Mayur Patel
    March 10, 2024 at 5:13 am

    how is it that it is still true today! March10’24 0011 EST
    worked like you say, it should!
    -m

    • Nick
      March 25, 2024 at 11:15 pm

      Glad it helped still! 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.