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
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