Reducing EBS volume size AWS | Abdul Haq

Reducing EBS volume size AWS

I recently shifted all my images and videos data from EBS volume to S3 as it was cheaper. After completing the shifting I had plenty of unused GBs of space left. I decided to reduce my EBS volume size assuming it would be as simple as it was to increase volume size. However that did not turn out to be the case and I end up spending two weeks figuring it out how to do it!

Thus, I have created the guide below for someone trying to do something similar, hoping to save their time.

Step 1:

Before doing anything else, take a snapshot of your volume. So in case of any blunder, your data is safe.

Step 2:

Create a new EC2 instance and volume. Make sure this instance is identical your current instance (same operating system and everything else) or else it won’t boot. I made this mistake and wasted 8 extra days stressing over it. This instance itself is not required but the volume created with it will be used. You may delete this instance once volume is created with it.

Step 3:

Create another new Amazon EC2 instance same as your existing instance (Very important). A micro or small instance should do. We only need this temporarily to run some commands and will delete it once our volume is reduced.

Step 4:

Detach the old, over-sized volume from its instance and attach it to the instance you created in step #3 above.

Mount the old volume as /dev/sdf/ (it will become /dev/xvdf).

Step 5:

Mount the new, smaller volume (created in step #2) as /dev/sdg (it will become /dev/xvdg).

Step 7:

Run this command:

sudo e2fsck -f /dev/xvdf1

Step 8:

If the last command runs without errors, go ahead and run this command:

sudo resize2fs -M -p /dev/xvdf1

Step 9:

The last line from the resize2fs command above will tell you how many 4k blocks are on your file system. Now, you need to calculate the number of 16MB blocks you need.

Use this formula:

blockcount * 4 / (16 * 1024)

Where blockcount is from the last line of the resize2fs command.

Round up this number to give yourself a small buffer. Save this result. We will use it soon.

Step 11:

Now run this command:

sudo dd bs=16M if=/dev/xvdf1 of=/dev/xvdg1 count=SavedResultFromPreviousStep

This may take a while to complete depending on how much data you have. This step performs the actual copying of data from the old, over-sized drive to the new, smaller drive.

Step 12:

When the copy finishes, run the following two commands:

sudo resize2fs -p /dev/xvdg1

sudo e2fsck -f /dev/xvdg1

These commands will resize and check that everything is good with your new file system.

Step 13:

If everything is good, shut down the temporary instance. Detach both the old and new volumes. Attach the new, small volume to your original EC2 instance. This time, mount the drive to your boot device (/dev/sda1).

Step 14:

Boot up your original EC2 instance and test that everything works well with the new, small volume.


I hope the above article provided you with helpful giude and if you still run into problems, you can contact me. I would love to help you, if I could. :)


Tags: ,


Please share if you found this useful


Recent Posts

Developing a WordPress theme

If you are here, I assume you have heard about WordPress before.  If not, let me tell you th...

Creating feed like Instagram Android

Few weeks back I showed how you can create profile similar to Instagram. You can see that article...

Reducing EBS volume size AWS

I recently shifted all my images and videos data from EBS volume to S3 as it was cheaper. After c...

Android Instagram like profile

Today I will show how you can create profile similar to Instagram's profile in android. It is mor...

top