
How to Increase and Decrease the Size of an Amazon EBS Volume
Amazon Elastic Block Store (EBS) allows you to increase the size of a volume dynamically without downtime. However, decreasing the size of an EBS volume is not supported directly, and you must follow a workaround.
1. Increasing the Size of an EBS Volume
Amazon EBS supports volume resizing while keeping data intact.
Resizing involves three steps:
Modify the EBS volume size
Extend the partition
Resize the file system
Steps to Increase EBS Volume Size (AWS Console)
Step 1: Modify the Volume
Open the AWS Management Console
Go to EC2 Dashboard → Elastic Block Store → Volumes
Select the EBS Volume you want to resize
Click Modify Volume
Increase the size (e.g., from 20GB to 50GB)
Click Modify → Confirm
AWS will resize the volume, and its state will change to
optimizing
.
Step 2: Extend the Partition (Linux)
Connect to the EC2 instance via SSH:
ssh -i your-key.pem ec2-user@your-ec2-instance-ip
Check the available disk space:
lsblk
Example Output:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda 202:0 0 50G 0 disk
└─xvda1 202:1 0 20G 0 part /
Resize the partition:
sudo growpart /dev/xvda 1
Resize the file system:
For ext4/xfs file systems, run:
sudo resize2fs /dev/xvda1 # For ext4
sudo xfs_growfs / # For XFS
Verify the new size:
df -h
Now, your EBS volume has been successfully expanded!
Step 2: Extend the Partition (Windows)
Open Disk Management
Right-click on the EBS volume
Click Extend Volume
Follow the wizard and expand the disk
Your EBS volume is now resized in Windows!
2. Decreasing the Size of an EBS Volume (Workaround)
Amazon EBS does not allow shrinking a volume directly.
Workaround: Create a new smaller volume and migrate data.
Steps to Reduce EBS Volume Size
Create a snapshot of the original EBS volume.
Create a new smaller EBS volume from the snapshot.
Attach the new volume to the EC2 instance.
Copy the data from the old volume to the new one.
Detach and delete the old volume.
Example (Using AWS CLI)
Create a snapshot of the existing volume:
aws ec2 create-snapshot --volume-id vol-0a1b2c3d4e5f6g7h8 --description "Backup before resizing"
Output:
{
"SnapshotId": "snap-1234567890abcdef0"
}
Create a smaller volume from the snapshot:
aws ec2 create-volume --snapshot-id snap-1234567890abcdef0 --size 30 --availability-zone us-east-1a
Attach the new volume to the instance:
aws ec2 attach-volume --volume-id vol-0987654321abcdef0 --instance-id i-0123456789abcdef0 --device /dev/xvdf
Copy the data:
sudo rsync -avxHAX /mnt/old-volume/ /mnt/new-volume/
Detach and delete the old volume:
aws ec2 detach-volume --volume-id vol-0a1b2c3d4e5f6g7h8
aws ec2 delete-volume --volume-id vol-0a1b2c3d4e5f6g7h8
Now, you have a smaller EBS volume with your data intact.
3. Summary
Operation | Supported by AWS? | Steps Required |
---|---|---|
Increase EBS Volume Size | Modify Volume → Extend Partition → Resize File System | |
Decrease EBS Volume Size | Create New Volume → Migrate Data → Delete Old Volume |
Would you like an automated script to handle EBS resizing?