
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:
1️⃣ Modify the EBS volume size
2️⃣ Extend the partition
3️⃣ Resize the file system
📌 Steps to Increase EBS Volume Size (AWS Console)
Step 1: Modify the Volume
1️⃣ Open the AWS Management Console
2️⃣ Go to EC2 Dashboard → Elastic Block Store → Volumes
3️⃣ Select the EBS Volume you want to resize
4️⃣ Click Modify Volume
5️⃣ Increase the size (e.g., from 20GB to 50GB)
6️⃣ Click Modify → Confirm
✅ AWS will resize the volume, and its state will change to optimizing
.
Step 2: Extend the Partition (Linux)
1️⃣ Connect to the EC2 instance via SSH:
ssh -i your-key.pem ec2-user@your-ec2-instance-ip
2️⃣ 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 /
3️⃣ Resize the partition:
sudo growpart /dev/xvda 1
4️⃣ Resize the file system:
For ext4/xfs file systems, run:
sudo resize2fs /dev/xvda1 # For ext4
sudo xfs_growfs / # For XFS
5️⃣ Verify the new size:
df -h
✅ Now, your EBS volume has been successfully expanded!
Step 2: Extend the Partition (Windows)
1️⃣ Open Disk Management
2️⃣ Right-click on the EBS volume
3️⃣ Click Extend Volume
4️⃣ 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
1️⃣ Create a snapshot of the original EBS volume.
2️⃣ Create a new smaller EBS volume from the snapshot.
3️⃣ Attach the new volume to the EC2 instance.
4️⃣ Copy the data from the old volume to the new one.
5️⃣ Detach and delete the old volume.
📌 Example (Using AWS CLI)
1️⃣ Create a snapshot of the existing volume:
aws ec2 create-snapshot --volume-id vol-0a1b2c3d4e5f6g7h8 --description "Backup before resizing"
📌 Output:
{
"SnapshotId": "snap-1234567890abcdef0"
}
2️⃣ Create a smaller volume from the snapshot:
aws ec2 create-volume --snapshot-id snap-1234567890abcdef0 --size 30 --availability-zone us-east-1a
3️⃣ Attach the new volume to the instance:
aws ec2 attach-volume --volume-id vol-0987654321abcdef0 --instance-id i-0123456789abcdef0 --device /dev/xvdf
4️⃣ Copy the data:
sudo rsync -avxHAX /mnt/old-volume/ /mnt/new-volume/
5️⃣ 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 | ✅ Yes | Modify Volume → Extend Partition → Resize File System |
Decrease EBS Volume Size | ❌ No | Create New Volume → Migrate Data → Delete Old Volume |
Would you like an automated script to handle EBS resizing? 🚀