Increase size of Amazone ec2 instance
Step by Step
This article demonstrates how one of our users increased a root EBS volume from 8GB to 30GB.
In order to accomplish this, we will show you how once you launch a Linux-based EC2 instance, you can increase the size of your EBS volume using snapshots. All you need to do is launch an instance, create a snapshot from the volume that is attached to the launched instance, then create a new, bigger volume.
Below is a step by step guide that will clarify how to perform this task:
- First, you need to successfully launch an EC2 instance with EBS as
its root device. The root EBS volume is used as a reference, so you can
follow the same step for all of the volumes.
- Next, connect the instance via PuTTY (in Windows machines) or an SSH client (in Linux machines). We are using PuTTY for our exercise.
- Run the command “df –h”. It will display the drive’s details before resizing.
- To increase the size of the root volume, since this is an EBS-backed instance, first stop the instance temporarily.
Using CLI:
ec2-stop-instances i-bc781c50
(assuming that the AWS CLI has already been set up on your machine.)
- Detach the existing volume from the instance.
Using CLI:
ec2-detach-volume vol-47b0d203
- Create a snapshot from the previously detached volume.
Using CLI:
ec2-create-snapshot vol-47b0d203 --description "Daily Backup"
- Provide an appropriate name for the snapshot.
- Details of the recently created snapshot can be found under the description tab in the snapshot area.
- Create a volume from the recently generated snapshot.
Using CLI:
ec2-create-volume --size 30 --region us-east-1 --availability-zone us-east-1a --type gp2
Note: In this case, the us-west-2 region is selected in the CLI instead of us-east-1 because the instance is running in US West.
- Now, you can resize the volume. Here, the user resized it from 8GB
to 30GB. All you have to do is specify the AZs and select the type of
the volume you need. (Note: The volume must be created in the AZ where
the present instance is in a stopped state. Otherwise, if the volume and
the instance are in different zones they cannot be attached.)
- Attach the new volume to the running instance.
Using CLI:
ec2-attach-volume vol-7bea883f -i i-bc781c50 -d /dev/xvda
- Identify the stopped instance from the list and attach it as the
root device. (It is very important to identify the root device drive and
only attach the new volume as the root device.)
- Start the instance after the new root volume is attached.
Using CLI:
ec2-start-instances i-bc781c50 - Log into the instance console using PuTTY or an SSH client.
(Note: This time, the public DNS will be different since the instance
was first stopped and then started. If you want to keep the same public
DNS, use an elastic IP.) If this is not your root volume and you are
attaching the volume as an additional volume to a Linux instance, you
should run the command “resize2fs ” to increase the size
of the new volume. As for the root volume, AWS will automatically
increase the file system according to the updated size.
- Run the command “df –h” again to check the size of the root device.
The above mentioned command displays that the size of the root device is now 30GB.
Note: In the steps above, the root volume size was increased from 8GB to 30GB. However, you can follow the same steps to increase the size of any additional attached volume to a running instance.
As you can see, snapshots provide a very handy option to back up data at a specific point in time while achieving HA and DR, as well. With this ability, we were able to change the size of the EBS volume shown above. N2Ws offers Cloud Protection Manager (CPM), which is an enterprise-class backup/recovery and disaster recovery solution for EC2. It is a software product that uses EBS volumes and RDS databases to automatically take snapshots at regular intervals. Additionally, you can set up policies and schedule backups for various targets.
Comments
Post a Comment