Resizing an EC2 Instance Volume
For standard (magnetic) volume types
The CloudFormation template install will default to standard magnetic EBS volume type. Magnetic does not support resizing, so you'll have to create a snapshot, create a new volume, and then then remount it.
Stop your EC2 instance
Go to EC2 and select your instance
Go to Actions > Instance State > Stop
In the EC2 instance details, make a note of the Availability zone (you'll need this later)
Also note the Root device mount path. For example, this might be
/dev/xvda
(you'll need this later too)Find your instance's EBS volume
A shortcut I like to use is to click on the Root device
/dev/xvda
link in the EC2 instance details. In the pop-up, click on the link next to EBS ID.Go to Actions > Create Snapshot. This creates a backup.
For the snapshot description, type in
SFTP Gateway snapshot
Add a tag.
- Key:
Name
- Value:
SFTP Gateway snapshot
Click Create Snapshot
Click the link provided to navigate to your snapshot.
Wait a few moments for the snapshot to create. Use the refresh button near the top right of the screen.
- Key:
Create a volume from the snapshot
Go to Actions > Create Volume
Select
General Purpose SSD (GP2)
as the Volume TypeChange the volume size
Change the Availability Zone to match your EC2 instance's AZ
Add a Tag so you can easily identify the volume later
Click Create Volume
Click the link to navigate to your Volume Id.
Unmount the magnetic volume
Find the original magnetic EBS volume. You can go back to your EC2 instance, and click on
/dev/xvda
again.Go to Actions > Detach Volume
Mount the resized GP2 volume
Find the resized GP2 EBS volume
Go to Actions > Attach volume
Select the SFTP Gateway instance from the drop down menu
For Device, enter the root device path (i.e.
/dev/xvda
, or whatever you noted earlier)Click Attach
Start the EC2 instance
Run the following command to make sure you're utilizing the new volume size
df -h
For GP2 volume types
(Note: most CloudFormation template installations default to standard magnetic EBS volume type. Please refer to the section above for resizing instructions)
The best approach would be to resize the EC2 instance volume. AWS provides instructions on how to do so here:
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-expand-volume.html
This document can be pretty intimidating. But here's a condensed version:
First, stop your EC2 instance.
Go to EC2 > Volumes and find your instance's volume.
Go to Actions > Create Snapshot. This creates a backup.
Go to Actions > Modify Volume, and increase the storage size. For now, specify 64 GB.
It'll take a while for the volume resize operation to complete. But under your volume's details, look for the "state". Once it is "optimizing", you can proceed.
Run the following (note the space between xvda and 1):
sudo growpart /dev/xvda 1
Run the following:
sudo resize2fs /dev/xvda1
Here's what's going on. Increasing the EC2 volume is a 3-step process. Imagine you're inflating 3 balloons nested inside each other. But you have to inflate the outer one first to make room for the inner ones.
- The outermost layer is the EBS volume. You increased this via the "Modify Volume" step in the AWS console.
- The middle layer is the partition. You increased this using
growpart
. You can uselsblk
to verify that you're using the full 64 GB volume. - The inner layer is the file system. You increased this using
resize2fs
. You usedf -h
to verify that you're using the full partition.
The documentation has a lot of explanation and tangents for edge cases that you can refer to. But the actual process is
just Modify Volume in the AWS console, and two commands: growpart
and resize2fs
.