Score:2

Decrease Size of EBS Volume attached to EC2 Instance

ua flag

I've created an EC2 instance with some 100 GB initial size, thereafter I realized this much size is not required, I've to decrease the size now.

What I tried?

  • Create a new volume with the desired size.
  • Attach new volume to ec2 instance.
  • Setup New volume (grub-install, EFI partition, etc)
  • Copy data from old_volume to new_volume.
  • Detach old volume.

But this process is a little bit complex as this can't be smoothly done by all the users, is there any better approach for this?

Tim avatar
gp flag
Tim
The approach you've taken is the only one I know that works. How many volumes do you have that are too large?
DilLip_Chowdary avatar
ua flag
Added my new approach in the answer, (bypass EFI setup process)
Score:1
ua flag

Here are the steps to migrate your ec2 instance data from large volume to small volume.

  • Create a new Instance with desired (reduced) volume size and name it temp-instance.

    • After the instance is in a running state and status checks are passed, stop the instance, detach this volume and name it as destination_vol
  • Attach destination_vol to the main instance.

  • Connect to the main instance and run the below commands.

  • Login as root

sudo su - 
  • Mount Volumes
mkdir /target

mount -t ext4 /dev/nvme1n1p1 /target

  • Copy data from src to dest
rsync -aHAXxSP / /target 
  • Unmount Volumes.
umount /target
  • Stop Main Instance
  • Detach both volumes.
  • Attach destination_vol in mount path /dev/sda1
  • Start the instance.

Note:

  • Make sure you set proper AMI, architecture, vpc, etc while creating a temp instance.

Tips

  • Stuck in Initializing state:

If you followed all the above steps properly and still your instance is in the initializing state, you can shutdown and restart the instance.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.