Is it possible to resize mounted partition over ssh?

Tanel Tammik asked:

Background: i was given SSH access to a Ubuntu 20.04 VPS that has root partition of 5G (sda total 25G). VPS provider says Linux admin can resize the /dev/sda1 partition.

$ sudo fdisk -l && df -h
Disk /dev/sda: 25 GiB, 26843545600 bytes, 52428800 sectors
Disk model: Virtual disk    
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xe1f10bb0

Device     Boot Start      End  Sectors Size Id Type
/dev/sda1  *     2048 10483711 10481664   5G 83 Linux
Filesystem      Size  Used Avail Use% Mounted on
udev            1.9G     0  1.9G   0% /dev
tmpfs           394M  788K  393M   1% /run
/dev/sda1       4.9G  3.0G  1.7G  64% /
tmpfs           2.0G     0  2.0G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           2.0G     0  2.0G   0% /sys/fs/cgroup
tmpfs           394M     0  394M   0% /run/user/1002

So i need to resize /dev/sda1 partition mounted to / over SSH. As far as i know, it is not possible.

Is it impossible, is it possible or has there been some miscommunications with the VPS provider? i am in contact with them through a third party.

My answer:

You can use the growpart utility to resize the partition to fill the available space. growpart expects the disk device and partition number as separate arguments. So you can resize the partition /dev/sda1 by: growpart /dev/sda 1. Note that the space is required. After that is done, you can resize the filesystem.

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.