Insert title here

Case Studies

Bringing your idea to life and in front of billions of eyes



Amazon EBS volumes: How to reduce Down to custom disk Size
aws (K.Praveen)

Have you ever launched an EC2 instance with Amazon EBS (Elastic Block Store) storage only to realize that your EBS storage is way over-allocated and you have no idea on how to reduce it?

Amazon’s Elastic Block Store Volumes are easy to use and expanding them is no problem at all, but for some reason, there’s no obvious way to reduce them. This is especially problematic when the EBS volume is mounted on the root.

It turns out that there’s nothing to worry about. I’ll take you through an easy way to reduce your volumes so you can hopefully save yourself some money.

Reducing AWS EBS Volumes

EC2 Instance with 20GB Amazon EBS Volume 

For the purpose of this exercise, I created an instance and launched it with a 20GB Amazon EBS volume:

Assuming we want to reduce this to 8GB, the first thing we will need to do is to make a note of the root volume’s block device name and our instance’s availability zone
Instance availability zone
So in my case, the details are
Block Device Name = /dev/sda1
Availability Zone = ap-southeast-2b

Stop the Instance:

Instance state drop down (Start, Stop, Reboot, Terminate) 

Create a snapshot of the root volume:

AWS EBS - Create a first snapshot of the root volume

Create a second Amazon EBS volume:

Using the snapshot, create a second volume – of the original size – in the same availability zone as your instance.
Amazon EBS - Create a second snapshot of the root volume
Hopefully, you will have something like this:
AWS EBS - Summary of Availability Zones

Create an empty 8GB Amazon EBS volume in the same availability zone

AWS EBS - Attaching both volumes to the instance
attach both volumes to the instance and again note all device name details.

Create 8GB Amazon EBS volume
Now, attach both volumes to the instance and again note all device name details.

Block Device Name Big Volume = /dev/sda1
Block Device Name Big Volume Snapshot = /dev/sdg
Block Device Name Small Volume = /dev/sdf

Restart the Instance and SSH in

Login:

ssh -i  ec2-user@ip-address

Create a file system for the 2 volumes you have created (Note: In Ubuntu I had to do a cat/proc/partitions to work out which device was which).

sudo mkfs -t ext4 /dev/xvdf
sudo mkfs -t ext4 /dev/xvdg

Create two mount directories and mount the new volumes.

sudo mkdir /mnt/small
sudo mount /dev/xvdf /mnt/small
sudo mkdir /mnt/snap
sudo mount /dev/xvdg1 /mnt/snap

Sync the files.

sudo rsync -aHAXxSP /mnt/snap/ /mnt/small

Unmount the smaller volume.

sudo umount /dev/xvdf

Stop the instance

Detach all volumes.
AWS EBS - Detaching all volumes
Attach the small volume to the Block Device Name from the first step.
Block Device Name = /dev/sda1
AWS EBS - Attaching the small volume to the Block Device Name from the first step
Now you can restart your instance and verify that it is working correctly.

 


Comments
Add Comment     See All Comments


zpltwjaplwr@gmail.com
I'm commenting to make you know what a excellent encounter our child gained viewing your web page. She figured out a wide variety of things, not to mention what it is like to have a wonderful coaching style to have the mediocre ones smoothly completely grasp a number of specialized issues. You actually surpassed her desires. I appreciate you for coming up with such invaluable, trustworthy, explanatory and easy tips about your topic to Lizeth. off white


ghhlzu@gmail.com
I am glad for commenting to make you be aware of what a brilliant experience my friend's daughter undergone visiting your blog. She mastered a lot of pieces, including what it is like to possess a very effective giving spirit to let many people clearly completely grasp specific impossible things. You really did more than our own desires. Thank you for distributing the practical, trustworthy, explanatory and also unique tips about your topic to Lizeth. goyard handbag


kfhdgoxd@gmail.com
I simply wanted to thank you so much yet again. I do not know the things that I would've achieved in the absence of the information documented by you over such a question. It has been a very terrifying setting in my view, nevertheless being able to see a new well-written style you dealt with it forced me to jump over gladness. I'm thankful for your assistance as well as hope that you recognize what a powerful job you happen to be putting in instructing people today via your webpage. I am certain you've never encountered all of us. birkin bag


zuuojcuhwjs@gmail.com
I would like to show my thanks to this writer just for rescuing me from this type of circumstance. As a result of surfing through the world-wide-web and meeting strategies which were not helpful, I was thinking my life was done. Living without the presence of solutions to the problems you have resolved by means of the write-up is a crucial case, as well as ones which may have badly damaged my entire career if I had not noticed your site. Your capability and kindness in handling all the details was very helpful. I don't know what I would've done if I hadn't come upon such a stuff like this. I can also at this time relish my future. Thank you so much for this specialized and amazing help. I won't hesitate to recommend the sites to any individual who requires assistance about this problem. jordan shoes


nrtzcqydo@gmail.com
I simply wanted to appreciate you all over again. I'm not certain the things I could possibly have made to happen without those pointers shared by you concerning my concern. Completely was a hard concern in my circumstances, nevertheless coming across a new expert form you handled that made me to jump with fulfillment. I'm happy for this support and as well , hope that you realize what an amazing job that you are providing educating many others thru your website. Probably you've never come across all of us. off white nike

-->
Tech Divinity cloud enable faster performance