我有一台运行 Canonical 最新 Ubuntu AMI 的服务器。EBS 启动卷的大小为 8GB。我知道我可以通过拍摄快照、创建新卷并在其上扩展分区来调整 EBS 卷的大小。如何在机器运行时增加卷的大小?如果这是不可能的,那么以最少的停机时间增加引导卷大小的首选方法是什么?
7 回答
我们可以使用新的 EBS Feature Elastic 卷增加卷大小,发布后我们需要按照以下步骤使用增加的大小,如下所示
假设您的音量为 16G,而您将其增加到 32GB。
$lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda 202:0 0 32G 0 disk
└─xvda1 202:1 0 16G 0 part /
要将 xvda1 从 16GB 扩展到 32GB,我们需要 growpart。growpart作为cloudutils的一部分提供
sudo apt install cloud-utils
安装 cloud-utils 后,执行 growpart 命令
sudo growpart /dev/xvda 1
现在 lsblk,将显示
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda 202:0 0 32G 0 disk
└─xvda1 202:1 0 32G 0 part /
但 df -h 只会显示 16GB
将 xvda1 扩展到 32GB 的最终命令是
sudo resize2fs /dev/xvda1
在 XFS 文件系统的情况下,
sudo xfs_growfs /dev/xvda1
谢谢彩蛋
Unfortunately it is not possible to increase the size of an Amazon EBS root device storage volume while the Amazon EC2 instance is running - Eric Hammond has written a detailed (I'm inclined to say the 'canonical' ;) article about Resizing the Root Disk on a Running EBS Boot EC2 Instance:
As long as you are ok with a little down time on the EC2 instance (few minutes), it is possible to change out the root EBS volume with a larger copy, without needing to start a new instance.
If you properly prepare the steps he describes (I highly recommend to test them with a throw away EC2 instance first to get acquainted with the procedure), you should be able to finish the process with a few minutes downtime only indeed.
Good luck!
这个 5 年前的问题的迟到答案
AWS 刚刚宣布了一项名为Elastic Volumes的新 EBS 功能,它允许您在使用卷时增加卷大小、调整性能或更改卷类型。
您可以在此处的 AWS 博客上阅读有关它的更多信息。
您只需要先创建其快照,然后从该快照创建另一个卷,一旦新卷准备好,将旧卷与实例分离并附加新卷。确保在开始此过程之前停止实例,并在完成后重新启动实例。
请参阅http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-expand-volume.html
这将适用于 xfs 文件系统只需运行此命令xfs_growfs /
我发现当试图增加在centos6上被报告为/dev/xvda1的根分区/dev/sda1时,我无法卸载卷以扩展分区。
我通过将原始卷挂载为 /dev/sda1 并将我的快照挂载为 /dev/sdb 来解决这个问题。然后我重新启动映像并使用 parted 调整 /dev/sdb1 分区的大小。
调整分区 /dev/sdb1 的大小后,我分离了两个卷并将新卷重新附加到 /dev/sda1 并运行 resize2fs /dev/xvda1。
你不能做这个。但是,如果您更关注停机时间而不是成本,您也许可以克隆您的主实例,将更大的 EBS 存储设备安装到您的系统,复制数据,然后将流量重定向到您的新实例。
如果您愿意,我最近使用 S3 的一种方法具有备份和部署到其他系统的媒介。因此,例如,您正在运行现有系统..设置一个脚本以每 N 分钟/小时/天将您的数据上传到 s3..然后编写一个脚本以在启动新实例时使用以下载该数据。如果您的数据不是像不断更新的那样,那么这应该可以正常工作(对我来说,我使用它来分发我的代码库的更新版本,而数据本身是在 ec2 数据库服务器上管理的)。
希望有帮助。