12_Resizing_a_Managed_Disk_In_Azure - Nirvan-Pandey/Azure_DOC GitHub Wiki

12_1: Introduction

In this lab, we will walk through the steps required to resize an existing data disk in an Azure virtual machine. This is often needed when the current disk space is insufficient for workloads or to improve performance.

12_2: Increasing the Size

Step1: Check current size

SSH into the VM in which we have attached our disk. (Here its Application Server)

lsblk

image

Step2: Navigate to managed disk.

Virtual Machine(Application-Server)-> Disk->Data Disk (1024 GiB)->Click on Disk

image

Step3: Increase the disk size.

Click on Disk-> Size+Performance -> Choose a bigger size (2048 GiB) -> Save

image

image

Size has been increased here.

image

Step4: Run lsblk & df -h into VM.

It is showing the old disk size of both physical disk and logical volumes are still the same. We need to scan to detect the changes made.

image

Scan it.

echo 1 | sudo tee /sys/class/block/sdc/device/rescan

sdc is my physical disk.

Step5: Rerun lsblk & df -h into VM.

image

As we can see the physical disk is increased but the partition and the logical volume is not increased.

12_3: Increase the partition to new size

Step1: We have to run below command to increase the size of partition.

growpart /dev/sdc 1

image

Step2: Check the size of partition.

parted /dev/sdc print

image

Here, we can see the size of the partition is increased.

But, the logical volume is not increased.

We will check logical volume(lv_u01) in a volume group (vg_u01) in detail by running the below command:

lvdisplay -am /dev/mapper/vg_u01-lv_u01

image

12_4: Resize the Physical Volume

Now we have to resize the physical volume, run the below command

pvresize /dev/sdc1

To check:

pvdisplay /dev/sdc1

image

We can check volume group allocated PE also, run the below command.

vgdisplay vg_u01

In below screenshot, we can see total PE,allocated PE and free PE

image

But Logical volume is still not increased:

image

12_5: Extending the Logical Volume and File System

Step 1: Extend the Logical Volume

Run the following command to extend the logical volume to utilize the newly available space:

lvextend -l +100%FREE /dev/mapper/vg_u01-lv_u01

This command tells LVM to allocate all available unassigned space in the volume group to the specified logical volume.

image

Step2: Verify the change.

We can see the logical volume size has increased by lsblk. However, the filesystem inside it might still report the old size.(when we use df -h)

image

Step 3: Resize the File System

To make the additional space usable, resize the file system:

resize2fs /dev/mapper/vg_u01-lv_u01

Note: This works for ext4 file systems. If you're using xfs, use xfs_growfs instead:

xfs_growfs /u01

image

Step 4: Re-Verify

After resizing, confirm the new size with:

image

We can now see the updated and extended size of your mount point.

12_6: Conclusion

In this lab, we resized an Azure managed disk and expanded it within the VM using LVM. We increased the disk size via the portal, rescanned the device, extended the partition, resized the physical and logical volumes, and finally expanded the file system. These steps ensure the VM can fully utilize the new disk space without downtime.