Reducing AWS EBS Volumes

|
| By Navneet Kashyap

AWS EBS

For example, we already have one instance with a 20 GB volume attached, and we want to reduce this to 8GB or 10 GB, or any size as per requirement, then first we have to note the root volume’s block device name.

AWS1

So in this case, the details are as follows
Block Device Name = /dev/sda1
Availability Zone = ap-souteast-2b

Stop the Instance:

AWS2

Create a snapshot of the root volume:
AWS3

Create a second Amazon EBS volume:

Using the snapshot feature, create a second volume with the original volume size in the same location.
AWS4

After that, you will have something like this:
AWS5

Create an desired size of empty volume or for example 8GB Amazon EBS volume in the same availability zone
AWS6

Now, attach both newly created volumes to the instance and again note down 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 just created.
sudo mkfs -t ext4 /dev/xvdf
sudo mkfs -t ext4 /dev/xvdg

Create two mount points and mount the new volumes with those.
sudo mkdir /mnt/small
sudo mount /dev/xvdf /mnt/small
sudo mkdir /mnt/snap
sudo mount /dev/xvdg1 /mnt/snap

Sync the files with mentioned switches/options.
sudo rsync -aHAXxSP /mnt/snap/ /mnt/small

Unmount the smaller volume.
sudo umount /dev/xvdf

Stop the instance
First detach all the volumes.
AWS7

Now, attach the decreased size volume to the Block Device Name in this step.
Block Device Name = /dev/sda1

AWS8
Now you can restart your instance and verify that it is working correctly.

Leave a Reply

Your email address will not be published. Required fields are marked *