Resize ext3 partition on a VPS live!

Many times you will purchase a VPS and go with the lowest resources you think you can get away with. As your website grows you may find you need to add more disk space.

This can be very easy to do with some basic tools in Linux. I will show you how to quickly and easily do this in Debian – but you shouldn’t have issue doing this in any other distro that includes fdisk and resize2fs.

First, you will need to have your disk expanded in the backend. This will have to be done by the VPS provider. Once the disk has been expanded you will want to reboot the machine. This will allow fdisk to see the larger disk.

The next step is to delete the current partition, and recreate it with the new larger size. Do not worry, the process of deleting a partition doesn’t actually remove any data, just the reference to the partition.

So run:

fdisk /dev/sda

Where sda is the disk in question.

The first command to run is: p which simply prints the current partition table.

Only one tiny little point took my attention: after creating the new partition, just before the reboot, it – naturally – gives an error saying “WARNING: Re-reading the partition table failed with error 16: Device or resource busy.” and at first look, it made me feel like it failed. But after reading next lines of the error it says it needs to reboot and makes sense that it just needs to do that, however that WARNING indicator is really annoying as a newbie linux user like something didn’t go well. Lesson learned from this experience once again: always read the messages until the end and make sure to understand what it actually means :)