2013-11-25 24 views

回答

12

我采取降低的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 
+0

感谢您的指示。我想指出倒数第二行有一个错误;该命令是正确的,但描述不正确。它实际上是指新调整大小的卷,而不是原始卷。 –

+0

dd行中的块数= 80? – wordsforthewise

+0

而且新FS的尺寸是否真的有必要? – wordsforthewise

0

从ezhilrean回答是好的,但有一个更简单的方法。

假设你有一个实例与在/ dev/sdf1上你的/ var分区,并想从300GB减少这200GB(假设有上的/ var数据< 200GB)

创建一个新的体积在相同AZ与原始卷 它使用根权限连接到该实例为/ dev/SDG 登录到实例

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 */new/

更新您的/ etc/fstab以使用/ var的新分区

/dev/sdg1 /var  ext4 defaults  0 0 

重启

init 6 

如果你需要你的/ var分区有标识的/ dev/sdf1上,你可以停止实例,分离这两个EBS卷,然后重新装上新的较小的一个为/ dev/sdf 请记住在执行此操作之前更改/ etc/fstab

+0

我们需要将卷附加到其他实例,然后我们需要将其减小并重新附加。 –