Sometimes when we use a virtual machine on some cloud platforms such as Azure, we might face the following scenario. The hard disk is running out of space. Thus we expand the size of that hard disk from the cloud platform's dashboard. After logging in to the system again, we find that the size of the disk is successfully expanded while the partition remains the same size.

If the type of partition table is MBR and the file system is Linux (e.g. ext4), we can run the following steps to expand the size of that partition.

Install cloud-guest-utils

sudo apt-get install cloud-guest-utils

Unmount the partition and expand its size

sudo umount /path/to/mount/folder
sudo growpart /dev/sda 1
sudo e2fsck -f /dev/sda1
sudo resize2fs /dev/sda1

Assuming /dev/sda is the hard disk device, and 1 is the number of the target partition.

Note that the commands are only tested in the case that the hard disk has one partition and this partition is resized to the full size of the expanded hard disk.

Tag:CloudOps

Add a new comment.