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 use
fdisk -lto find out the drive’s name (e.g.
- Create a new physical volume for this partition using
- Extend the existing volume group to include this, e.g.
vgextend VOLUMEGROUP /dev/sdc5, where
VOLUMEGROUPis the name of the volume group. You can find out what the volume group is called by using the command
- Extend the logical volume to include this extra space, e.g.
lvextend -l +100%FREE /dev/VOLUMEGROUP/root
- Resist the filesystem. The command for this varies depending on what filesystem is currently installed, so for
ext4this would be
resize2fs, and in my case for
After which, you should be able to type
df -h and see increased disk space available to you.