Sub topic 9
Resizing and retuning volumes with Elastic Volumes
This chapter assumes you can create and attach a volume, and that you know how to mount one on Linux. Elastic Volumes lets you change a volume's size, type, IOPS, or throughput while it stays attached and in use. You do not need to detach it or stop the instance.
What you can change
- Increase the size. You cannot shrink a volume.
- Change the volume type, for example gp2 to gp3.
- Change provisioned IOPS and throughput on types that support them.
Some limits apply. The new settings must be valid for the target type. For example, gp3 has its own IOPS and throughput ranges. After a modification, you must wait before you can modify the same volume again (typically six hours).
The modification workflow
A change has two parts. EBS changes the volume first. Then you extend the file system so the operating system can use the new space.
The volume is usable in the optimizing state. Performance may be between the old and new settings until it reaches completed.
Step 1: Modify the volume
aws ec2 modify-volume \
--volume-id vol-0123456789abcdef0 \
--size 200 \
--iops 6000
aws ec2 describe-volumes-modifications \
--volume-ids vol-0123456789abcdef0Check the ModificationState field in the output. You can extend the file system once it shows optimizing or completed.
Step 2: Extend the file system
The file system still has its old size. Run lsblk to see that the block device is larger than its mount.
sudo xfs_growfs /dataxfs_growfs takes the mount point. For ext4, use sudo resize2fs /dev/nvme1n1 instead, with the device name. If the volume has a partition, such as a root volume, grow the partition first with sudo growpart /dev/nvme0n1 1. Then grow the file system.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| `modify-volume` fails on the size | You asked for a smaller size | Create a smaller volume and copy the data. |
| Change rejected shortly after another | Waiting period after the last modification | Wait, then retry. |
| `df -h` shows the old size | File system not extended | Run `xfs_growfs` or `resize2fs`. |
| `xfs_growfs` says it is not a mount point | You passed the device name | Pass the mount path, such as `/data`. |
| IOPS above what you expect | Instance limit applies | Check the instance's EBS limits. |
Choosing between resize and replace
Modify in place when you need more space or want to move from gp2 to gp3. Create a new volume from a snapshot when you need to shrink, or when a change is not supported. Moving from gp3 to a cheaper type may need this approach, depending on the types involved. Check the current limits in the EBS documentation before you plan the change.
Exercise
You raised a volume from 100 GiB to 200 GiB, and describe-volumes-modifications shows optimizing. Running df -h still shows 100 GiB. What is the next step, and why?
Show answer
Extend the file system, for example sudo xfs_growfs /data for XFS. EBS has enlarged the block device, but the file system keeps its old size until you grow it. The optimizing state is already late enough to do this.
Exercise
You need to reduce a 500 GiB volume to 200 GiB. Can Elastic Volumes do it?
Show answer
No. Elastic Volumes only increases size. Create a new 200 GiB volume, copy the data over, and then retire the old volume.