Reduce EC2 Root Volume Size

0. Tested to work on Ubuntu 14.04
1. Stop source instance
2. Snapshot source instance root volume
3. Create a clone volumn from the snapshot from #2, name it INSTANCEKEY-origin
4. Launch a new instance with a volumn of the desired smaller size (don’t delete volumn on instance termination)
5. Terminate the new instance (all we need is the volume)
6. Name the volume from the new instance INSTANCEKEY-target
7. Attach INSTANCEKEY-origin volume to the source instance, as /dev/sdg
8. Attach INSTANCEKEY-target volume to the source instance, as /dev/sdf
9. Start source instance again
10. Run following:

mkfs -t ext4 /dev/xvdf1
mkdir /mnt/origin
mkdir /mnt/target
mount /dev/xvdg /mnt/origin
mount /dev/xvdf1 /mnt/target
rsync -aHAXxSP /mnt/origin/ /mnt/target

11. Check LABEL (all 3 should be the same) via

blkid

12. From the result of blkid, remember UUID of /dev/sda1 and /dev/sdf, replace UUID from /dev/sda1’s to /dev/sdf’s

vim /mnt/target/boot/grub/grub.cfg
:%s/FROM/TO/g

13. Poweroff the source instance
14. Detach all volumes
15. Attach the target volume to the source instance, with Device set to /dev/sda1
16. Start the source instance again, should be working with the new volume
17. Delete the snapeshot created from #2
18. Delete the original volume of the source instance, and the volume created from step 3 (i.e. the origin volume)
19. Update your snapshot backup script with the new volume id

Reference:

http://cloudacademy.com/blog/amazon-ebs-shink-volume/
http://serverfault.com/questions/673048/how-to-reduce-aws-ebs-root-volume-size