Resize partition at VPS without losing data

Odin asked:

I have small VPS server with 40 GB disk space. I bought extra 40 GB and now I would like to extend / partition size.

My partitions looks like this:

Partitions size

/dev/vda1 is /boot and /dev/vda5 is my /. My VPS provider added /dev/vda2. I’m not sure if this is correct but I’ve tried to remove /dev/vda5 and /dev/vda2 and create /dev/vda5 but I don’t have that option, I only can re-create devices with ID 2-4 and not 5 where my / is.

My answer:

There is a utility named growpart that will safely grow partitions once your provider has expanded your virtual disk. The only trick in your case is that they have unnecessarily created an extended/logical DOS partition when it was not needed. Thus you will have to resize the extended partition, then the logical one it contains.

sudo apt install cloud-guest-utils

The growpart utility accepts the disk and partition number as separate arguments, so to resize /dev/vda2 you will write:

sudo growpart /dev/vda 2

Resize the extended partition /dev/vda2 first, then resize /dev/vda5 the same way.

sudo growpart /dev/vda 2
sudo growpart /dev/vda 5

Now you should be able to resize your filesystem. If it is ext4 then resize2fs /dev/vda5 will work. For XFS, use xfs_growfs /.

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.