DEV Community

Cover image for Day 50: Expanding EC2 Instance Storage for Development Needs
Thu Kha Kyawe
Thu Kha Kyawe

Posted on

Day 50: Expanding EC2 Instance Storage for Development Needs

Lab Information

The Nautilus DevOps Team has recently been informed by the Development Team that their EC2 instance is running out of storage space. This instance, crucial for development activities, is named xfusion-ec2 and currently has an attached volume of 8 GiB. To accommodate the increasing data requirements, the storage needs to be expanded to 12 GiB. This change should ensure that the expanded space is immediately available for use within the instance without disrupting ongoing activities.

Identify Volume: Find the volume attached to the xfusion-ec2 instance.

Expand Volume: Increase the volume size from 8 GiB to 12 GiB.

Reflect Changes: Ensure the root (/) partition within the instance reflects the expanded size from 8 GiB to 12 GiB.

SSH Access: Use the key pair located at /root/xfusion-keypair.pem on the aws-client host to SSH into the EC2 instance.

Lab Solutions

Step 1: Identify the volume attached to xfusion-ec2

From the aws-client host:

aws ec2 describe-instances \
  --filters "Name=tag:Name,Values=xfusion-ec2" \
  --query "Reservations[].Instances[].BlockDeviceMappings[].Ebs.VolumeId" \
  --output text
Enter fullscreen mode Exit fullscreen mode

✔ This returns a volume ID like:

vol-057ed3f876c222e27

Step 2: Expand the EBS volume (8 GiB → 12 GiB)

aws ec2 modify-volume \
  --volume-id vol-057ed3f876c222e27 \
  --size 12
Enter fullscreen mode Exit fullscreen mode

Verify modification state

aws ec2 describe-volumes-modifications \
  --volume-ids vol-057ed3f876c222e27
Enter fullscreen mode Exit fullscreen mode

Wait until:

"Progress": "100"

✅ At this point, AWS has expanded the disk
❌ The OS does NOT see the new space yet

Step 3: SSH into the EC2 instance

From aws-client:

ssh -i /root/xfusion-keypair.pem ec2-user@<PUBLIC_IP>
Enter fullscreen mode Exit fullscreen mode

Step 4: Verify current disk size (inside EC2)
lsblk

You will see:

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
xvda 202:0 0 12G 0 disk
├─xvda1 202:1 0 8G 0 part /
├─xvda127 259:0 0 1M 0 part
└─xvda128 259:1 0 10M 0 part /boot/efi

This is expected.

Step 5: Expand the root partition
Identify root disk

Usually one of these:

/dev/xvda

/dev/nvme0n1

# Grow the partition
sudo growpart /dev/xvda 1
# Since this is Amazon Linux, the root filesystem is XFS.
sudo xfs_growfs /
Enter fullscreen mode Exit fullscreen mode

Step 7: Verify final result ✅

df -h /
Enter fullscreen mode Exit fullscreen mode

Expected output:

Filesystem Size Used Avail Use%
/dev/xvda1 12G ...

✔ Root partition now reflects 12 GiB
✔ No reboot required
✔ No downtime


Resources & Next Steps
📦 Full Code Repository: KodeKloud Learning Labs
📖 More Deep Dives: Whispering Cloud Insights - Read other technical articles
💬 Join Discussion: DEV Community - Share your thoughts and questions
💼 Let's Connect: LinkedIn - I'd love to connect with you

Credits
• All labs are from: KodeKloud
• I sincerely appreciate your provision of these valuable resources.

Top comments (0)