Increase the Linux VM Disk Size in Azure
Increase the disk size from Azure portal first
Expand a disk partition and filesystem
To use an expanded disk, expand the underlying partition and file system.
1. SSH to your VM with the appropriate credentials. You can see the public IP address of your VM with az vm show:
Azure CLI Copy
az vm show --resource-group myResourceGroup --name myVM -d --query [publicIps] --o tsv
2. Expand the underlying partition and filesystem.
a. If the disk is already mounted, unmount it:
bash Copy
sudo umount /dev/sdc1
b. Use parted to view disk information and resize the partition:
bash Copy
sudo parted /dev/sdc
View information about the existing partition layout with print. The output is similar to the following example, which shows the underlying disk is 215 GB:
bash Copy
GNU Parted 3.2 Using /dev/sdc1 Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) print Model: Unknown Msft Virtual Disk (scsi) Disk /dev/sdc1: 215GB Sector size (logical/physical): 512B/4096B Partition Table: loop Disk Flags: Number Start End Size File system Flags 1 0.00B 107GB 107GB ext4
c. Expand the partition with resizepart. Enter the partition number, 1, and a size for the new partition:
bash Copy
(parted) resizepart Partition number? 1 End? [107GB]? 215GB
d. To exit, enter quit.
3. With the partition resized, verify the partition consistency with e2fsck:
bash Copy
sudo e2fsck -f /dev/sdc1
4. Resize the filesystem with resize2fs:
bash Copy
sudo resize2fs /dev/sdc1
5. Mount the partition to the desired location, such as /datadrive:
bash Copy
sudo mount /dev/sdc1 /datadrive
6. To verify the data disk has been resized, use df -h. The following example output shows the data drive /dev/sdc1 is now 200 GB:
bash Copy
Filesystem Size Used Avail Use% Mounted on /dev/sdc1 197G 60M 187G 1% /datadrive
Issue:
Cannot extend the /dev/sda1 root filesystem.
Root Cause:
There were /dev/sda2 and /dev/sda5 partition created after /dev/sda1, because the sda1 partition require continuous block, so that we need delete partition sda2 and sda5 before sda1 expansion.
Action done:
We deleted sda2 and sda5 then expend sda1 successfully. But it seems some meta data corrupted before, the VM cannot boot after the first sda1 expansion.
Then we restore the VM from snapshot backup, and tried deleted sda2 and sda5, extend sda1 again, this time the sda1 extend successfully. VM can bootup successfully too.
We do NOT recommend creating partition after sda1, because if you need extend sda1 next time, you will need delete those partition again for sda1 extending.
Current VM status