Amazon ec2 如何在不丢失数据的情况下减少EBS卷容量?
我希望在不丢失数据的情况下减少EBS卷容量 我想将容量从1 TB更改为200 GBAmazon ec2 如何在不丢失数据的情况下减少EBS卷容量?,amazon-ec2,Amazon Ec2,我希望在不丢失数据的情况下减少EBS卷容量 我想将容量从1 TB更改为200 GB 请提供详细的操作步骤。我减少EBS根卷的方法如下: 停止(而不是终止)目标实例,并分离根EBS卷。或者,您可以快照根卷(或使用现有快照)并从该卷创建新的EBS卷。(例如/dev/xvda1) 注意:您在上述步骤中使用的卷将被更改-因此,如果您尚未创建快照,则可能需要创建快照 Create a new EBS volume that is the desired size (e.g. /dev/xvdg) Lau
请提供详细的操作步骤。我减少EBS根卷的方法如下: 停止(而不是终止)目标实例,并分离根EBS卷。或者,您可以快照根卷(或使用现有快照)并从该卷创建新的EBS卷。(例如/dev/xvda1) 注意:您在上述步骤中使用的卷将被更改-因此,如果您尚未创建快照,则可能需要创建快照
Create a new EBS volume that is the desired size (e.g. /dev/xvdg)
Launch an instance, and attach both EBS volumes to it
Check the file system (of the original root volume): (e.g.) e2fsck -f /dev/xvda1
Maximally shrink the original root volume: (e.g. ext2/3/4) resize2fs -M -p /dev/xvda1
Copy the data over with dd:
Choose a chunk size (I like 16MB)
Calculate the number of chunks (using the number of blocks from the resize2fs output): blocks*4/(chunk_size_in_mb*1024) - round up a bit for safety
Copy the data: (e.g.) dd if=/dev/xvda1 ibs=16M of=/dev/xvdg obs=16M count=80
Resize the filesystem on the new (smaller) EBS volume: (e.g.) resize2fs -p /dev/xvdg
Check the file system (of the new volume): (e.g.) e2fsck -f /dev/xvdg
Detach your new EBS root volume, and attach it to your original instance
Ezhillean的回答是可以的,但有一个更简单的方法 假设您在/dev/sdf1上有一个/var分区的实例,您希望将其从300GB减少到200GB(假定/var上的数据小于200GB) 在与原始卷相同的AZ中创建新卷 将其作为/dev/sdg附加到实例 使用root权限登录到实例
fdisk /dev/sdg
n (for New)
p (for Primary)
Accept defaults for other fdisk options
w (for Write)
然后fdisk将退出。现在需要在新分区上创建一个文件系统
mkfs.ext4 /dev/sdg1 (presuming that ext4 was used on existing partition)
接下来,在临时挂载点挂载新分区
mkdir /new
mount /dev/sdg1 /new
现在,复制您的数据
cd/var
cp-ax*/新/
更新/etc/fstab以使用/var的新分区
/dev/sdg1 /var ext4 defaults 0 0
重新启动
init 6
如果您需要/var分区具有标识符/dev/sdf1,您可以停止该实例,分离两个EBS卷,并将新的较小的卷重新连接为/dev/sdf记住在执行此操作之前更改/etc/fstab您是在说根EBS卷吗,或者附加到实例的辅助EBS卷?如果它不是根卷--附加新卷,使用fdisk-l获取其标识符,使用mkfs-t ext4/dev/xvdk将其装入文件系统,mount it mount/dev/xvdk temp_mount/,rsync the old to the new rsync-a/old_mount temp_mount/,取消连接两个EBS驱动器并重新连接新驱动器。我们需要将卷连接到其他实例,然后需要将其缩小并重新连接。感谢您的指导。我想指出倒数第二行有个错误;命令正确,但描述不正确。它实际上指的是新调整大小的卷,而不是原始卷。dd行中计数为80的块数是否真的需要调整新FS的大小?