How to add new EBS volume and extend the file system partition on EC2 machine?
How to add new EBS volume and extend the file system partition on EC2 machine?

How to add new EBS volume and extend the file system partition on EC2 machine?

Author
Created
Jun 7, 2024
Tags
EC2 EBS
File system extension
Text
This document detailed out the steps on how to extend the EC2 EBS volume. This is useful when disk is full and we want to add more space to the device.
When running an Amazon EC2 instance, you might encounter a situation where your EBS (Elastic Block Store) volume runs out of space. Instead of migrating to a new instance or dealing with storage constraints, you can easily extend your existing EBS volume. This guide will walk you through the necessary steps to extend your EBS volume and increase your storage capacity seamlessly.
 
💡
Prerequisites
  • An AWS account with the necessary permissions to modify EBS volumes.
  • An existing EC2 instance with an EBS volume that needs to be extended.
  • AWS CLI installed and configured on your local machine (optional but recommended)

Step 1: Stop the EC2 Instance (Optional)

For best practice, it's recommended to stop your EC2 instance before modifying the EBS volume. However, you can extend the volume without stopping the instance if you are using modern file systems that support online resizing.
  1. Stop the Instance:
      • Open the EC2 Dashboard in the AWS Management Console.
      • Select the instance.
      • Click Instance State > Stop.

Step 2: Modify the EBS Volume

  1. Navigate to the EBS Volumes:
      • In the EC2 Dashboard, click on Volumes under the Elastic Block Store section.
  1. Select the Volume:
      • Identify the volume you want to extend. Select it by clicking the checkbox next to the volume ID.
  1. Modify the Volume:
      • Click on Actions > Modify Volume.
      • In the Modify Volume dialog box, increase the Size field to the desired value (in GiB).
      • Click Modify.
  1. Confirmation:
      • Confirm the modification in the pop-up that appears. AWS will start resizing the volume in the background.

Step 3: Monitor the Volume Modification

  1. Monitor Progress:
      • Navigate to the Events tab to monitor the progress of the volume modification.
      • The volume state will change from modifying to optimizing. You can start using the extended space while it is in the optimizing state.

Step 4: Extend the File System

After the volume modification is complete, you need to extend the file system on your EC2 instance to utilize the new space. The steps vary depending on the file system type.

For Linux Instances

  1. Connect to Your Instance:
      • Use SSH to connect to your EC2 instance.
  1. Check the Current File System:
      • Use the lsblk command to identify the device name (e.g., /dev/xvda1).
  1. Extend the File System:
      • For ext4 File System:
        • sudo resize2fs /dev/xvda1
      • For XFS File System:
        • sudo xfs_growfs -d /
  1. Verify the Changes:
      • Use the df -h command to verify the new size of the file system.