You’re running an EC2 instance, disk usage hits 95%, deployments start failing, and eventually you get “No space left on device”.
AWS lets you expand EBS volumes live, without stopping the instance. Here’s the whole procedure.
When you resize an EBS volume in the AWS Console, AWS does expand the underlying disk. Your OS inside the instance has no idea, though. The partition and filesystem still report the old size.
So after “supposedly” resizing, you get this:
$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 58G 55G 3.1G 95% / Still 58G even though you just upgraded to 120GB. That’s the part you have to fix yourself.
120 GB)This works without stopping your instance for gp2, gp3, io1, and io2 volume types. Give it a minute or two to finish before moving on.
Connect to the instance and check the current disk layout:
lsblk The kernel recognises the new disk size, but the partition hasn’t been extended:
NAME MAJ:MIN SIZE
nvme0n1 259:0 120G <- new size is here
└─nvme0n1p1 259:1 58G <- but partition is still old sudo growpart /dev/nvme0n1 1 That extends partition 1 to use all the available space on the disk.
Now resize the filesystem to fill the newly expanded partition.
For ext4, which is the Ubuntu default:
sudo resize2fs /dev/root
# or
sudo resize2fs /dev/nvme0n1p1 For XFS, the default on Amazon Linux 2 and AL2023:
sudo xfs_growfs -d / df -h You should see the full size now:
Filesystem Size Used Avail Use% Mounted on
/dev/root 117G 55G 62G 47% / From 3.1G free to 62G free.
| Step | Command |
|---|---|
| Check disk layout | lsblk |
| Check filesystem usage | df -h |
| Grow partition | sudo growpart /dev/nvme0n1 1 |
| Extend filesystem (ext4) | sudo resize2fs /dev/root |
| Extend filesystem (XFS) | sudo xfs_growfs -d / |
The whole process happens on a live instance, so there’s no downtime. The AWS-side change takes a few minutes, so wait for the volume state to show “optimizing” or “completed” before you run any of the commands.
Device names vary. Use lsblk to confirm whether your disk is /dev/xvda or /dev/nvme0n1 rather than copying the names above.
Ubuntu uses ext4; Amazon Linux 2 and AL2023 use XFS by default. That decides which of the two resize commands you need.
Expanding EC2 storage is two parts: resize the volume in AWS, then extend the partition and filesystem inside the OS. Once you know the steps it takes under two minutes and the instance never goes offline.
If you keep hitting disk limits, put a CloudWatch alarm on disk usage so you catch it earlier.