Increase Amazon EBS Volume of a Linux EC2 instance

Increasing the size of an EBS volume is, sadly, not as easy as tweaking a value. Amazon AWS does not support changing the volume size on the fly, but there are ways to increase the size. They require you to stop the running instance. You can view the process of increasing the EBS volume size as like exchanging a real hard disc in a computer with a larger one. If you would just throw the old one out and put the new one in, it would be empty. The same happens here with the EBS volume.

Create a new EBS volume

To create a clean snapshot I prefer to stop the EC2 instance before creating a new snapshot of the EBS volume. This snapshot can be used to created a new EBS volume. To create the snapshot, open the AWS Console and select ‘Snapshot’ in the left menu.

Advertisements

Amazon_AWS_EBS_Create_Volume

The new volume will be restored from the snapshot. Even if the snapshot is smaller then the new disk, the restore still works. Before you start with this, it is important to make sure that the EBS volume and the EC2 are in the same Zone. So check the currently used volume and note its “Zone”.

The easiest way to create a new volume is to select the Snapshot previously created and press “Create Volume”. Now you can define the new size of the volume. Make sure to choose the correct Zone while creating!

Change the Volume in the EC2 instance

With the new volume created, at the size you need, the new EBS volume needs to be attached to the EC2 instance. This is done by ‘Detaching’ the old volume, and then ‘Attaching’ the new volume to the ‘Device’.

To do this, you need to note down the “Attachment” details. You should find something like “/dev/sda”. With this noted down, go to Volume and select “Action” and then “Detach Volume”. Be patient now as this can take some time, and you may even have to “Force Detach”.

Once the volume is detached, you can select the new volume and attach it to the EC2 instance. With the new volume attached, the EC2 instance can be started.

Resize the partition

With the new and bigger volume, you can login but you will notice that the hard disc is still the same small size. To use the full size of the new volume, the file system needs to be resized. As soon as you are logged in to your EC2 instance, execute the following shell command:

resize2fs /dev/xvda1

After that, if you execute “df -h” you will see the increased size of the disc.


Read more of my posts on my blog at http://blog.tinned-software.net/.

This entry was posted in Linux Administration and tagged , , . Bookmark the permalink.