This can be done using the cloud-utils package:
For Debian and Ubuntu
apt install cloud-utils -y
For CentOS
yum install cloud-utils -y
Now the cloud-utils are installed, we need to know the name of the existing partition. use the following command to search for a partition mounted to “/”:
mount | grep ' / '
Example output:
/dev/sda3 on / type ext4 (rw,noatime,data=ordered)
Remember the first part (“/dev/sda3” in the example above). To expand the partition, use the following commands:
growpart /dev/sda 3
resize2fs /dev/sda3
And that’s all it takes to expand your existing partition on Debian and Ubuntu and CentOS.