How to extend existing partition to a larger size

moon yi 60 Reputation points
2024-08-20T14:27:00.21+00:00

Hi

I have created a Linux (Rehat) VM and allocated 128GB, but I would like to increase the size to 512GB.

How do i increase this and make a partion so that the Linux would recognize it? Also after the partion is created, how do i increase the size of /home/moon?

Cheers

Moon

Azure Disk Storage
Azure Disk Storage
A high-performance, durable block storage designed to be used with Azure Virtual Machines and Azure VMware Solution.
629 questions
0 comments No comments
{count} votes

Accepted answer
  1. Nehruji R 7,556 Reputation points Microsoft Vendor
    2024-08-21T09:15:41.2733333+00:00

    Hello moon yi,

    Greetings! Welcome to Microsoft Q&A Platform.

     

    To increase the size of your Linux VM disk to 512GB and then resize the /home/moon directory,

    Please try the steps below:

    1.To increase the Disk Size in Azure:  

    • The simplest way to resize the disk itself is go to Azure Portal, locate your VM and deallocate or stop it.  
    • Then go to settings navigate to the Disks section under your VM settings.  
    • For both standard and premium disk, in properties section You will find the Size field. Click on the disk you want to resize  
    • For premium storage it will be field with 3 size options 128GB, 512GB, 1024GB as for your requirement 512GB, Increase the size to 512GB and save the changes.  
    • Then start your VM again.

     

    2.To create a New Partition on the VM:  

    • Login to Your Linux VM and check how many disks you have used and how much space you have.  - Run the command to identify the disk you resized like /dev/sda, "lsblk" this will list all available block devices.  
    • Use the fdisk tool to create a new partition "sudo fdisk /dev/sda"    

    Inside fdisk, follow these steps: Type 'n' to create a new partition.

    Choose 'p' for a primary partition.

    Select 'a' partition number like 3 if /dev/sda1 and /dev/sda2 are existing.

    Press Enter to accept the default start sector.

    Specify the end sector or press Enter to allocate the rest of the available space.

    Type w to write the changes and exit fdisk

    • Format the new partition with the ext4 file system

    "sudo mkfs.ext4 /dev/sda3"     

    Replace /dev/sda3 with the actual partition identifier.  

    • Create a mount point

    "sudo mkdir /mnt/newdisk" and mount the new partition "sudo mount /dev/sda3 /mnt/newdisk".

    If you need to extend a specific directory like /home/moon, you can either move the new partition there or resize the existing partition using lvextend and resize2fs if it's part of a logical volume, "$ sudo resize2fs /dev/sdaX"

    -Make sure the partition mounts automatically on reboot,

    sudo nano /etc/fstab

    Add the following line "/dev/sda3 /mnt/newdisk ext4 defaults 0 0" Replace /dev/sda3 and /mnt/newdisk with your actual partition and mount point.

    • Verify the new partition is mounted and recognized by Linux by using the command df -h.

     

     

    A similar SO thread: https://stackoverflow.com/questions/26471342/how-to-increase-hd-size-of-linux-running-on-vmware, https://learn.microsoft.com/en-us/answers/questions/1192060/how-to-initialize-attached-data-disk-to-linux-vm-i

     

    reference: https://learn.microsoft.com/en-us/azure/virtual-machines/linux/expand-disks?tabs=rhellvm#identifyDisk

     

    Hope this answer helps! please let us know if you have any further queries. I’m happy to assist you further.

    Please "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Luis Arias 6,621 Reputation points
    2024-08-20T14:31:08.4633333+00:00

    Hi please follow this thread https://learn.microsoft.com/en-us/answers/questions/615098/disk-resizing-problem

    If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.

    Regards,

    Luis

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.