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.
- 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
- Navigate to the EBS Volumes:
- In the EC2 Dashboard, click on
Volumes
under theElastic Block Store
section.
- Select the Volume:
- Identify the volume you want to extend. Select it by clicking the checkbox next to the volume ID.
- Modify the Volume:
- Click on
Actions
>Modify Volume
. - In the
Modify Volume
dialog box, increase theSize
field to the desired value (in GiB). - Click
Modify
.
- 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
- Monitor Progress:
- Navigate to the
Events
tab to monitor the progress of the volume modification. - The volume state will change from
modifying
tooptimizing
. 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
- Connect to Your Instance:
- Use SSH to connect to your EC2 instance.
- Check the Current File System:
- Use the
lsblk
command to identify the device name (e.g.,/dev/xvda1
).
- Extend the File System:
- For ext4 File System:
- For XFS File System:
sudo resize2fs /dev/xvda1
sudo xfs_growfs -d /
- Verify the Changes:
- Use the
df -h
command to verify the new size of the file system.