Amazon EC2 flexibility: replacing a root volume in an instance

Time for some Amazon EC2 love.

Currently, our main servers are running on Amazon EC2. This last week, for a reason still unknown, we ran into a lack of disk space problem. The solution is to replace the disk, which in normal circumstances could be really bad… But with EC2, after understanding a little better how it works, this was simple and quick. And application downtime could be reduced to a minimum – around 20 minutes if I remember correctly – but this depends totally on the volume size.

These are the steps I had to take:

  • Stop the EC2 instance;
  • Take a snapshot of its volume;
  • Create a new volume, based on that snapshot, but with the desired new size;
  • Detach the old volume from the instance, attach the new, bigger one;
  • Start the instance again;
  • Execute ‘resize2fs /dev/sda1’ to make the linux installation aware of the new space.

Just remember to do all of this in the same availability zone, you cannot attach a volume from one zone into an instance from another one. You can use the command ‘df’ to check if the resize was successful.

Finally, the last step was to re-associate the correct IP address, so that everything works again as if nothing had happened.

This entry was posted in misc. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s