不断增长的 Amazon EBS 卷大小

发布于 2024-07-13 15:10:53 字数 1459 浏览 10 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

柏林苍穹下 2024-07-20 15:10:53

您可以增加存储空间,但不能即时完成。 您需要拍摄当前块的快照,添加一个新的、更大的块并重新附加您的快照。

此处有一个简单的演练,基于使用 Amazon 的 EC2 命令行工具

You can grow the storage, but it can't be done on the fly. You'll need to take a snapshot of the current block, add a new, larger block and re-attach your snapshot.

There's a simple walkthrough here based on using Amazon's EC2 command line tools

北陌 2024-07-20 15:10:53

如果需要,您不能简单地“插入”更多空间,但可以使用快照调整分区大小。

步骤如下:

  1. 卸载 ebs 卷
  2. 创建 ebs 快照
  3. 添加具有更多空间的新卷
  4. 重新创建分区表并调整大小
    文件系统
  5. 挂载新的 ebs 卷

查看 http://aws.amazon.com/ebs/ - EBS快照:

快照还可用于实例化多个新卷,
扩大卷的大小或移动
跨可用区的卷。
当创建新卷时,有
创建它的选项基于
现有的 Amazon S3 快照。 在那里面
场景中,新卷开始为
原卷的精确复制品。
通过选择性地指定不同的
卷大小或不同
可用区,此功能
可以用作增加
现有卷的大小或
在新的卷中创建重复的卷
可用区。 如果您选择
使用快照来调整卷大小,
你需要确定你的文件系统
或应用程序支持调整大小
设备。

You can't simply 'bump in' more space on the fly if you need it, but you can resize the partition with a snapshot.

Steps do to this:

  1. unmount ebs volume
  2. create a ebs snapshot
  3. add new volume with more space
  4. recreate partition table and resize
    filesystem
  5. mount the new ebs volume

Look at http://aws.amazon.com/ebs/ - EBS Snapshot:

Snapshots can also be used to instantiate multiple new volumes,
expand the size of a volume or move
volumes across Availability Zones.
When a new volume is created, there is
the option to create it based on an
existing Amazon S3 snapshot. In that
scenario, the new volume begins as an
exact replica of the original volume.
By optionally specifying a different
volume size or a different
Availability Zone, this functionality
can be used as a way to increase the
size of an existing volume or to
create duplicate volumes in new
Availability Zones. If you choose to
use snapshots to resize your volume,
you need to be sure your file system
or application supports resizing a
device.

梦醒时光 2024-07-20 15:10:53

我遵循了所有的答案,恕我直言,所有人都缺少一些东西。

如果您按照以下步骤操作,您可以增加 EBS 卷并保留数据(这不适用于根卷)。 为简单起见,我建议使用 AWS consule 创建快照,...您也可以使用 AWS 命令​​行工具来执行此操作。

我们在这里不涉及根卷。

转到您的 AWS 控制台:

  1. 关闭您的实例(仅持续几分钟)
  2. 分离您计划增长的卷(例如 /dev/xvdf)
  3. 创建该卷的快照。
  4. 使用您刚刚创建的快照创建一个更大尺寸的新卷
  5. 将新卷附加到您的实例
  6. 启动您的实例

SSH 连接到您的实例:

 $ sudo fdisk -l

这将为您提供如下内容:

Disk /dev/xvdf: 21.5 GB, 21474836480 bytes
12 heads, 7 sectors/track, 499321 cylinders, total 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xd3a8abe4

    Device Boot      Start         End      Blocks   Id  System
/dev/xvdf1            2048    41943039    20970496   83  Linux

记下 StartId 价值观。 (在本例中为 2048 和 83)

使用 fdisk 删除分区 xvdf1 并创建一个完全从同一块 (2048) 开始的新分区。 我们将给它相同的 Id (83):

$ sudo fdisk /dev/xvdf 

Command (m for help): d
Selected partition 1

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 
Using default value 1
First sector (2048-41943039, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): 
Using default value 41943039

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 83

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

此步骤在这里有很好的解释:http://litwol.com/content/fdisk-resizegrow-physical-partition-without-losing-data-linodecom

差不多完成了,我们只需挂载卷并运行 resize2fs

: ebs 卷:(我的位于 /mnt/ebs1)

$ sudo mount /dev/xvdf1 /mnt/ebs1

并调整其大小:

$ sudo resize2fs -p /dev/xvdf1

resize2fs 1.42 (29-Nov-2011)
Filesystem at /dev/xvdf1 is mounted on /mnt/ebs1; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 2
Performing an on-line resize of /dev/xvdf1 to 5242624 (4k) blocks.
The filesystem on /dev/xvdf1 is now 5242624 blocks long.

ubuntu@ip-xxxxxxx:~$ 

完成! 使用 df -h 验证新大小。

I followed all the answer, all have something missing with all respect.

If you follow these steps you can grow your EBS volume and keep your data (this is not for the root volume). For simplicity I am suggesting to use AWS consule to create snapshot,... you can do that using AWS command line tools too.

We are not touching the root volume here.

Goto your AWS console:

  1. Shutdown your instance ( it will be for a few minutes only)
  2. Detach the volume you are planning to grow (say /dev/xvdf)
  3. Create a snapshot of the volume.
  4. Make a new volume with a larger size using the snapshot you just created
  5. Attach the new volume to your instance
  6. Start your instance

SSH to your instance:

 $ sudo fdisk -l

This gives your something like:

Disk /dev/xvdf: 21.5 GB, 21474836480 bytes
12 heads, 7 sectors/track, 499321 cylinders, total 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xd3a8abe4

    Device Boot      Start         End      Blocks   Id  System
/dev/xvdf1            2048    41943039    20970496   83  Linux

Write down Start and Id values. (in this case 2048 and 83)

Using fdisk ,delete the partition xvdf1 and create a new one that starts exactly from the same block (2048). We will give it the same Id (83):

$ sudo fdisk /dev/xvdf 

Command (m for help): d
Selected partition 1

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 
Using default value 1
First sector (2048-41943039, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): 
Using default value 41943039

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 83

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

This step is explained well here: http://litwol.com/content/fdisk-resizegrow-physical-partition-without-losing-data-linodecom

Almost done, we just have to mount the volume and run resize2fs:

Mount the ebs volume: (mine is at /mnt/ebs1)

$ sudo mount /dev/xvdf1 /mnt/ebs1

and resize it:

$ sudo resize2fs -p /dev/xvdf1

resize2fs 1.42 (29-Nov-2011)
Filesystem at /dev/xvdf1 is mounted on /mnt/ebs1; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 2
Performing an on-line resize of /dev/xvdf1 to 5242624 (4k) blocks.
The filesystem on /dev/xvdf1 is now 5242624 blocks long.

ubuntu@ip-xxxxxxx:~$ 

Done! Use df -h to verify the new size.

怼怹恏 2024-07-20 15:10:53

只要您可以接受几分钟的停机时间,Eric Hammond 写了一篇关于在正在运行的 EBS 实例上调整根磁盘大小的好文章:http://alestic.com/2010/02/ec2-resize-running-ebs-root

As long a you are okay with a few minutes of downtime, Eric Hammond has written a good article on resizing the root disk on a running EBS instance: http://alestic.com/2010/02/ec2-resize-running-ebs-root

神也荒唐 2024-07-20 15:10:53

所有很棒的建议,我想我应该添加我找到的这篇文章,该文章涉及使用 Amazon Web UI 工具扩展 Windows Amazon EC2 EBS 实例以执行必要的更改。 如果您不习惯使用 CLI,这将使您的升级变得更加容易。

http://www.tekgoblin .com/2012/08/27/aws-guides-how-to-resize-a-ec2-windows-ebs-volume/

感谢 TekGoblin 发布本文。

All great recommendations, and I thought I'd add this article I found, which relates to expanding a Windows Amazon EC2 EBS instance using the Amazon Web UI tools to perform the necessary changes. If you're not comfortable using CLI, this will make your upgrade much easier.

http://www.tekgoblin.com/2012/08/27/aws-guides-how-to-resize-a-ec2-windows-ebs-volume/

Thanks to TekGoblin for posting this article.

久随 2024-07-20 15:10:53

您现在可以通过 AWS 管理控制台执行此操作。 该过程与其他答案中的过程相同,但您不再需要进入命令行。

You can now do this through the AWS Management Console. The process is the same as in the other answers but you no longer need to go to the command line.

享受孤独 2024-07-20 15:10:53

顺便说一句:与物理磁盘一样,使用 LVM 可能会很方便; 例如:

http://www.davelachapelle.ca/guides/ubuntu-lvm-guide/
http://www.centos.org/docs/5/html/Cluster_Logical_Volume_Manager/

最大优点:它允许动态添加(或删除)空间。

它还可以轻松地在实例之间移动。

注意事项:

  • 必须提前配置,
  • 简单的 JBOD 设置意味着如果丢失一个“磁盘”,您将失去一切

BTW: As with physical disks, it might be handy to use LVM; ex:

http://www.davelachapelle.ca/guides/ubuntu-lvm-guide/
http://www.centos.org/docs/5/html/Cluster_Logical_Volume_Manager/

Big advantage: It allows adding (or removing) space dynamically.

It can also easily be moved between/among instances.

Caveats:

  • it must be configured ahead of time
  • a simple JBOD setup means you lose everything if you lose one "disk"
你怎么这么可爱啊 2024-07-20 15:10:53

我的步骤:

  1. 停止实例,
  2. 找到附加到实例的 ebs 卷并创建它的快照
  3. 使用上面的快照创建一个具有更大磁盘空间的新卷。 不幸的是,aws 控制台上用于创建快照的 UI 几乎无法使用,因为它列出了 aws 上的所有快照。 使用命令行工具要容易得多,如下所示:

    ec2-create-volume -s 100 --snapshot snap-a31fage -z us-east-1c 
      
  4. 从实例中分离现有的 ebs(较小)卷

  5. 将新的(较大)卷附加到实例,并确保将其连接到实例期望的同一设备(在我的例子中是 /dev/sda1)
  6. 启动实例

您就完成了!

除了上述步骤 3 之外,您还可以使用 aws 管理控制台执行所有操作。

另请注意,如下所述:

https://serverfault。 com/questions/365605/how-do-i-access-the-attached-volume-in-amazon-ec2

您的 ec2 实例上的设备可能是 /dev/xv*,而 aws Web 控制台告诉您它是 /开发/s*。

My steps:

  1. stop the instance
  2. find the ebs volume attached to the instance and create a snapshot of it
  3. create a new volume with bigger disk space using the above snapshot. Unfortunately the UI on the aws console to create a snapshot is almost unusable because it's listing all the snapshots on aws. Using command line tool is a lot easier, like this:

    ec2-create-volume -s 100 --snapshot snap-a31fage -z us-east-1c
    
  4. detach the existing ebs (smaller) volume from the instance

  5. attach the new (bigger) volume to the instance, and make sure attach it to the same device the instance is expecting (in my case it is /dev/sda1)
  6. start the instance

You are done!

Other than step 3 above, you can do everything using the aws management console.

Also NOTE as mentioned here:

https://serverfault.com/questions/365605/how-do-i-access-the-attached-volume-in-amazon-ec2

the device on your ec2 instance might be /dev/xv* while aws web console tells you it's /dev/s*.

緦唸λ蓇 2024-07-20 15:10:53

对于 Windows 操作系统,请使用命令“diskpart”,请查看此处:使用 http://support.microsoft.com /kb/300415
以下是我对非根磁盘(基本非动态磁盘)执行的步骤。

拍摄快照后,卸载旧的 EBS 卷(例如 600GB)并创建一个更大的 EBS 卷(例如 1TB)并安装这个新的 EBS 卷- 您必须在命令提示符下让 Windows 了解大小调整(从 600GB 到 1TB)(以管理员身份运行)

diskpart.exe

选择磁盘=9

选择音量=Z

延长

[我的磁盘 9,卷标记为 Z,是从大小为 600GB 的 ec2 快照创建的大小为 1TB 的卷 - 我想将 600GB 调整为 1TB,因此可以按照上面的操作执行此操作的步骤。]

Use command "diskpart" for Windows OS, have a look here : Use http://support.microsoft.com/kb/300415
Following are the steps I followed for a non-root disk (basic not dynamic disk)

Once you have taken a snapshot, dismounted the old EBS volume (say 600GB) and created a larger EBS volume (say 1TB) and mounted this new EBS volume - you would have to let Windows know of the resizing (from 600GB to 1TB) so at command prompt (run as administrator)

diskpart.exe

select disk=9

select volume=Z

extend

[my disk 9,volume labelled Z, was a volume of size 1TB created from an ec2-snapshot of size 600GB - I wanted to resize 600GB to 1TB and so could follow the above steps to do this.]

我偏爱纯白色 2024-07-20 15:10:53

如果您的操作系统支持,我强烈建议所有 EBS 卷使用逻辑卷管理器 (LVM)。 Linux 发行版通常都是这样。 它很棒有几个原因。

  1. 逻辑卷的大小调整和移动可以实时完成,因此您可以添加创建另一个更大的 EBS 卷,将其作为物理卷 (PV) 添加到 LVM 池,而不是需要停机的整个离线快照操作,将逻辑卷 (LV) 移动到其中,从池中删除旧的物理卷,并删除旧的 EBS 卷。 然后,您只需调整逻辑卷的大小,并调整其上的文件系统的大小。 这根本不需要停机!

  2. 它将您的存储从“物理”设备中抽象出来。 无需停机或更改挂载点/fstab 即可跨设备移动分区非常方便。

如果 Amazon 能够动态调整 EBS 卷的大小,那就太好了,但使用 LVM 就没有必要了。

I highly recommend Logical Volume Manager (LVM) for all EBS volumes, if your operating system supports it. Linux distributions generally do. It's great for several reasons.

  1. Resizing and moving of logical volumes can be done live, so instead of the whole offline snapshot thing, which requires downtime, you could just add create another larger EBS volume, add it to the LVM pool as a physical volume (PV), move the logical volume (LV) to it, remove the old physical volume from the pool, and delete the old EBS volume. Then, you simply resize the logical volume, and resize the filesystem on it. This requires no downtime at all!

  2. It abstracts your storage from your 'physical' devices. Moving partitions across devices without needing downtime or changes to mountpoints/fstab is very handy.

It would be nice if Amazon would make it possible to resize EBS volumes on-the-fly, but with LVM it's not that necessary.

◇流星雨 2024-07-20 15:10:53

如果您的根卷是 xfs 文件系统,则运行此命令 xfs_growfs /

if your root volume is xfs file system then then run this command xfs_growfs /

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文