大网数据广告活动
服务器运维问答

Decrease Size of EBS Volume attached to EC2 Instance

· 52CE 我爱测

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 in…

问题原文

原帖链接 · 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
  • 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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2022-11-04)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。