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.
-
Login to Azure Portal
- Head over to the Azure Portal and log in with your credentials.
-
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.
-
Access the Disks Section
- On the left-hand sidebar under Settings, find and click on the Disks option.
-
Select the Disk to Extend
- You’ll see a list of attached disks. Click on the disk that you want to resize.
-
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.
-
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:
-
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>
-
Verify the Disk Size
- Before making changes, verify the current disk size using:
df -h
-
Identify the Disk
- Use the
lsblk
command to list all block devices and identify the disk you resized:
lsblk
- Use the
-
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 andN
with the partition number.
-
Resize the File System
- Now resize the file system to take advantage of the expanded partition:
sudo resize2fs /dev/sdX
-
Verify the Changes
- To confirm the file system has been extended, run:
df -h
For Windows VMs:
-
Connect via Remote Desktop
- Open Remote Desktop Connection on your local machine and connect to your Windows VM.
-
Open Disk Management
- Press
Windows + X
and select Disk Management. Here, you’ll see the resized disk with unallocated space.
- Press
-
Extend the Volume
- Right-click the partition you want to extend and choose Extend Volume.
-
Use the Extend Volume Wizard
- Follow the wizard prompts to allocate the unallocated space to the existing partition.
-
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.
Top comments (0)