Is it possible to resize mounted partition over ssh?
Solution 1:
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.
Solution 2:
I do this all the time on VMs, using parted
and resize2fs
:
$ sudo parted /dev/sda
(parted) resizepart 1 100%
(parted) quit
$ sudo partprobe /dev/xvda
$ sudo resize2fs -p /dev/xvda1
Obviously you need free space on the sda disk after the first partition.
partprobe
(comes with parted
) is necessary to get kernel to reread partition table.
resize2fs
to resize an ext* filesystem can normally be done online, but it can only grow filesystems. Other Linux filesystems will have other resizing commands; most can only grow online, not shrink.
Use print
command in parted
before and after resizepart
if unsure.