How to Extend a Disk on Azure: A Step-by-Step Guide

DevOpshelianDevOpshelian
4 min read

Azure provides a flexible infrastructure for managing virtual machines (VMs), but as your usage grows, you might find the need to expand the disk space allocated to a VM. Whether you're running out of storage or anticipating future growth, extending a disk on Azure is a simple yet crucial task. In this guide, we’ll walk through how to increase the size of your Azure-managed disks and extend that space within your operating system, whether it’s Windows or Linux.

Why Would You Need to Extend a Disk?

Over time, your VM might accumulate more data than anticipated. For example:

  • Applications may grow and require more storage.
  • Logs or databases might expand, eating up your available disk space.
  • You're adding new services or applications that need more room.

Extending a disk in Azure allows you to allocate additional storage without replacing the VM or disrupting your workflow.

Step 1: Increase the Disk Size on Azure Portal

The first step in extending a disk is to adjust its size within the Azure platform.

  1. Login to Azure Portal

    • Head over to the Azure Portal and log in with your credentials.
  2. Navigate to Your Virtual Machine

    • Use the search bar at the top of the portal to locate your virtual machine. Once found, click on it to open the VM’s overview page.
  3. Access the Disks Section

    • On the left-hand sidebar under Settings, find and click on the Disks option.
  4. Select the Disk to Extend

    • You’ll see a list of attached disks. Click on the disk that you want to resize.
  5. Resize the Disk

    • In the disk's settings, increase the disk size by entering a new value. Be sure to select a size greater than the current one.
  6. Save Your Changes

    • Once you've entered the new size, click Save to apply the changes. Azure will automatically begin resizing the disk.

Step 2: Extend the Disk Inside the Virtual Machine

Now that you’ve increased the size of the disk on Azure, it’s time to expand the partition and file system within your VM so it can make use of the additional space.

For Linux VMs:

  1. Connect to the VM

    • Use SSH to connect to your Linux VM. If you're on Windows, you can use tools like PuTTY or the built-in Windows Terminal.
      ssh <username>@<public-IP-of-VM>
      
  2. Verify the Disk Size

    • Before making changes, verify the current disk size using:
      df -h
      
  3. Identify the Disk

    • Use the lsblk command to list all block devices and identify the disk you resized:
      lsblk
      
  4. Extend the Partition

    • If your VM uses LVM (Logical Volume Manager), run the following command to extend the logical volume:
      sudo lvextend -l +100%FREE /dev/mapper/<volume-group-name>-<logical-volume-name>
      
    • If your VM uses a standard partition, you can resize it using growpart:
      sudo growpart /dev/sdX N
      
      Replace sdX with your disk identifier and N with the partition number.
  5. Resize the File System

    • Now resize the file system to take advantage of the expanded partition:
      sudo resize2fs /dev/sdX
      
  6. Verify the Changes

    • To confirm the file system has been extended, run:
      df -h
      

For Windows VMs:

  1. Connect via Remote Desktop

    • Open Remote Desktop Connection on your local machine and connect to your Windows VM.
  2. Open Disk Management

    • Press Windows + X and select Disk Management. Here, you’ll see the resized disk with unallocated space.
  3. Extend the Volume

    • Right-click the partition you want to extend and choose Extend Volume.
  4. Use the Extend Volume Wizard

    • Follow the wizard prompts to allocate the unallocated space to the existing partition.
  5. Verify the Extended Disk

    • Once complete, the partition will now use the full disk size. You can verify this in This PC under your drive properties.

Conclusion

Extending a disk on Azure is a straightforward process, but it requires both actions in the Azure Portal and adjustments within the virtual machine’s operating system. Whether you’re running Linux or Windows, following these steps will help you efficiently expand your storage and avoid running out of space on your critical workloads. As your infrastructure grows, knowing how to scale your VM’s storage becomes an essential skill.


By following these steps, you'll ensure that your Azure VMs remain scalable and flexible as your storage needs grow.

0
Subscribe to my newsletter

Read articles from DevOpshelian directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

DevOpshelian
DevOpshelian