So I have followed Eric's wonderful article here:

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>

up vote 6 down vote accepted

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:

rsync -PaSHAX /bigvol/ /smallvol/

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.

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.

  1. Create a new EBS volume that is the desired size (e.g. /dev/xvdg)
  2. Launch an instance, and attach both EBS volumes to it

  3. Check the file system (of the original root volume): (e.g.) e2fsck -f /dev/xvda1

  4. Maximally shrink the original root volume: (e.g. ext2/3/4) resize2fs -M -p /dev/xvda1

  5. Copy the data over with dd:

    1. Choose a chunk size (I like 16MB)
    2. 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

    3. Copy the data: (e.g.) dd if=/dev/xvda1 ibs=16M of=/dev/xvdg obs=16M count=80

  6. Resize the filesystem on the new (smaller) EBS volume: (e.g.) resize2fs -p /dev/xvdg

  7. Check the file system (of the original root volume): (e.g.) e2fsck -f /dev/xvdg

  8. Detach your new EBS root volume, and attach it to your original instance

  • I think this one should be the right answer. I tried the previous one. That ask me to rsync all files to the new volume. Which is not working at all. The new volume can not be bootup. But this answer works! Thanks @cyberx86, you saved my life! – agate Jun 21 '16 at 6:53
  • Doesn't work on Ubuntu 16 – cudds Jan 9 at 21:13

protected by Tom O'Connor May 6 '14 at 15:06

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.