When working on a medium size EC2 instance, running Debian 6, I ran out of free space. The root partition had fully grown into its 1GB EBS volume. 1GB was a default setting and I should have changed this before I started working.
You can use “df -h” to check how much free disk space you have remaining (man page).

No disk space!
So I cant just mount another disk because all my work is in /dev/sda1 (root).
By work I mean a PostgreSQL database, my Python app and ProFTPD. Normally I could just admit defeat and start a new EC2 instance but then I wouldn’t have a blog post. There could be times when you wouldn’t want to do that anyway.
So.. I’m not at the magical level where I can unmount and re-mount the disk the OS resides on while it is running.
The solution is to create a new EBS volume, copy the file system using the EBS ‘Snapshot’ feature and then attach it to your server instance.
How to fix
It’s an easy job and the downtime is only a few minutes.
- Create a new larger EBS volume and load the ‘Snapshot’

- Detach the EBS volume currently being used by the EC2 instance
- Attach the larger EBS volume, containing the snapshot
- Start the EC2 instance
- Assign any Elastic Ip’s you need
- Log in via SSH
- Reclaim the new space (The OS won’t do this on its own), see below
Claim the new free space
The command to claim unused space on your hard drive is resize2fs. Read about it first because you can specify some things like which disk to use. Run time may be a few minutes and there wont be any output to stdout until its complete. Allow it to finish or append the command with an &.
As root just execute:
resize2fd /dev/sda1
If that doesn’t work then try:
resize2fs /dev/xvda1
quick note: “xvda” – this is a Xen Virtual Disk, explained
Finally, execute df to check it worked. Output should be like the top picture with a small % under use.
In future
In my haste I used the wizard to set up a Debian ‘Squeeze’ instance. The Amazon Machine Image (AMI) came with a 1GB hard drive (EBS). It’s at that point you could attach a larger EBS just for the job you are working on. That would also be cool as you could detach (unmount) it and attach (mount) on another EC2 instance without having to take servers offline.
More info
This article saved me:
http://alestic.com/2010/02/ec2-resize-running-ebs-root
This issue seams pretty common:
http://stackoverflow.com/questions/6151695/ec2-instace-on-amazon-and-i-am-greeted-with-no-space-left-on-the-disk
Amazon official documentation:
http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/using.html


