In Linux, it is possible to expand an existing filesystem over multiple disk drives. I recently had to do this for a few VPS as part of my day job, since they were running out of disk space and causing some instability with one of our core services.
Here’s how to do it, mainly for my own benefit, for when I inevitably have to do it again and have forgotten how…
- First, after you have connected your new drive (either physically or virtually), you need to create a new logical partition on that drive using
cfdisk
. You can usefdisk -l
to find out the drive’s name (e.g./dev/sdc
) - Create a new physical volume for this partition using
pvcreate
, e.g.pvcreate /dev/sdc
5 - Extend the existing volume group to include this, e.g.
vgextend VOLUMEGROUP /dev/sdc5
, whereVOLUMEGROUP
is the name of the volume group. You can find out what the volume group is called by using the commandvgdisplay
. - Extend the logical volume to include this extra space, e.g.
lvextend -l +100%FREE /dev/VOLUMEGROUP/root
- Resize the filesystem. The command for this varies depending on what filesystem is currently installed, so for
ext4
this would beresize2fs
, and in my case forxfs
this isxfs_growfs
. E.g.xfs_growfs /dev/VOLUMEGROUP/root
After which, you should be able to type df -h
and see increased disk space available to you.