Yesterday I had to grow a live filesystem on a server in EC2, without downtime. I do this just infrequently enough to not quite remember all the details without poking around the internet, so I’m documenting it all in one place.
Grow the volume
- Log into the EC2 console and find your instance. In the description tab, look at the block devices (bottom right as of August 2019) and find the volume you need to grow and get its volume ID.
- Find that volume in the EBS volumes list. Now is a good time to name it something useful like “InstanceName /data01” if you haven’t already named it.
- Click Modify Volume, then give it a new size. It may take a minute or two to finish growing the volume, you’ll see a percentage displayed.
Resize the filesystem
- Log into the instance and start a
tmux
orscreen
session to do all the work in. Getting disconnected in the middle of resizing the filesystem would be bad. - Use
lsblk
to confirm that the EBS block device has increased to the size you expect. - If you have partitioned your drive, do
sudo growpart /dev/xyz1 0
to grow the partition. - Check
/etc/fstab
to see what format the filesystem is. - If you’re using xfs,
sudo xfs_growfs /dev/DEVICE
. If you’re using ext2, ext3 or ext4, dosudo resize2fs /dev/DEVICE
. If you’re using ext2 or ext3, seriously consider replacing this filesystem with an ext4 one during your next downtime window. - Wait. Depending on how much larger the EBS volume has become and the instance type, it can take several minutes for the filesystem to finish growing.
- Confirm the new size with
df