问题原文
原帖链接 · DilLip_Chowdary · CC BY-SA 4.0
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?
已采纳解答
原帖链接 · DilLip_Chowdary · CC BY-SA 4.0
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
- After the instance is in a running state and status checks are passed, stop the instance, detach this volume and name it as
Attach
destination_volto 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_volin 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.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
