So I have followed Eric's wonderful article here: http://alestic.com/2009/12/ec2-ebs-boot-resize
This was the code basically that helped me increase the default size of the AMI:
ec2-run-sintances ami-ID -n 1 --key keypair.pem --block-device-mapping "/dev/sda1=:250"
Running Ubuntu 11.10 I didn't even have to re-size the disk afterwards, it was immediately a 250GB drive.
How do I go about decreasing the default size of the AMI???
I tried:
ec2-run-sintances ami-ID -n 1 --key keypair.pem --block-device-mapping "/dev/sda1=:100"
Obviously... but I was told:
Client.InvalidBlockDeviceMapping: Volume of size 100GB is smaller than snapshot ####### <250>
The approach I take to decreasing an EBS root volume is as follows:
Stop (not terminate) the target instance, and detach the root EBS volume. Alternatively, you can snapshot the root volume (or use an existing snapshot) and create a new EBS volume from that. (e.g. /dev/xvda1)
Note: the volume you use from the step above will be altered - so you may want to take a snapshot if you didn't already.
Launch an instance, and attach both EBS volumes to it
Check the file system (of the original root volume): (e.g.)
e2fsck -f /dev/xvda1
Maximally shrink the original root volume: (e.g. ext2/3/4)
resize2fs -M -p /dev/xvda1
Copy the data over with dd:
Calculate the number of chunks (using the number of blocks from the resize2fs output):
blocks*4/(chunk_size_in_mb*1024) - round up a bit for safety
Copy the data: (e.g.)
dd if=/dev/xvda1 ibs=16M of=/dev/xvdg obs=16M count=80
Resize the filesystem on the new (smaller) EBS volume: (e.g.)
resize2fs -p /dev/xvdg
Check the file system (of the original root volume): (e.g.)
e2fsck -f /dev/xvdg
Detach your new EBS root volume, and attach it to your original instance
The best way to go about reducing the size is to create an empty new (small) volume and copy the file system over from an old (big) volume.
EBS boot AMIs are based on snapshots. If you own the AMI, then you can create a volume from the snapshot to copy it. Attach both volumes to a running instance for the copy.
My favorite rsync options on Ubuntu are:
These options preserve things like ownership, permissions, links, and much more.
Detach the volumes and create a snapshot of the new smaller one.
Register the new (small) snapshot as an AMI, making sure to specify the same architecture and AKI (kernel) as the original AMI.