Amazon EC2 和 EBS 磁盘空间问题

发布于 2024-09-27 14:37:12 字数 610 浏览 6 评论 0原文

我在协调 EBS 卷上的可用空间时遇到问题。根据AWS控制台,该卷为50GB并附加到一个实例。

如果我通过 ssh 连接到该实例并执行 df -h,我会得到以下输出:

Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              15G   13G  3.0G  81% /
udev                  858M   76K  858M   1% /dev
none                  858M     0  858M   0% /dev/shm
none                  858M   72K  858M   1% /var/run
none                  858M     0  858M   0% /var/lock
none                  858M     0  858M   0% /lib/init/rw

我对 AWS 还很陌生。我将此解释为“已连接一个设备,其容量为 15GB。更重要的是,您的空间快用完了!”

任何人都可以指出控制台中公布的空间与实例上显示的空间之间明显差异的原因吗?

非常感谢

提前

I am having a problem reconciling the space available on my EBS volume. According to the AWS console the volume is 50GB and is attached to an instance.

If I ssh to this instance and do a df -h, I get the following output:

Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              15G   13G  3.0G  81% /
udev                  858M   76K  858M   1% /dev
none                  858M     0  858M   0% /dev/shm
none                  858M   72K  858M   1% /var/run
none                  858M     0  858M   0% /var/lock
none                  858M     0  858M   0% /lib/init/rw

I am pretty new to AWS. I interpret this as "there is a device attached and it has 15GB capacity. Whats more, you're nearly out of space!"

Can anyone point out the cause of the apparent discrepancy between the space advertised in the console and what is displayed on the instance?

Many thanks in advance

S

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

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

发布评论

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

评论(9

冷…雨湿花 2024-10-04 14:37:12

是的,问题很简单。该卷仅与实例关联,但未挂载。

检查 AWS 控制台上安装的驱动器 - 最有可能的是 /dev/sdf

然后(在 ubuntu 上):

sudo mkfs.ext3 /dev/sdf
sudo mkdir /ebs
sudo mount /dev/sdf /ebs

第一行使用 ext3 文件系统类型格式化卷。这是相当标准的——但根据您的使用情况(例如应用程序服务器、数据库服务器……),您也可以选择另一个,例如 ext4xfs

第二个命令创建一个安装点,第三个命令将其安装到其中。这意味着新卷实际上将位于 /ebs。它现在也应该显示在 df 中。

最后但并非最不重要的一点是,也许还可以向 /etc/fstab 添加一个条目,以使其能够防止重新启动。

Yes, the issue is simple. The volume is only associated with the instance, but not mounted.

Check on the AWS console which drive it is mounted as - most likely /dev/sdf.

Then (on ubuntu):

sudo mkfs.ext3 /dev/sdf
sudo mkdir /ebs
sudo mount /dev/sdf /ebs

The first line formats the volume - using the ext3 file system type. This is pretty standard -- but depending on your usage (e.g. app server, database server, ...) you could also select another one like ext4 or xfs.

The second command creates a mount point and the third mounts it into it. This means that effectively, the new volume will be at /ebs. It should also show up in df now.

Last but not least, maybe also add an entry to /etc/fstab to make it reboot-proof.

櫻之舞 2024-10-04 14:37:12

也许原始 15 GB 卷已克隆到 50 GB 卷,但随后未调整大小?

请参阅本教程,了解如何克隆和调整大小:如何在不丢失数据的情况下增加现有 AWS EC2 Linux (Ubuntu) 实例上的磁盘空间

希望有所帮助。

Perhaps the original 15 GB Volume was cloned into a 50 GB volume but then not resized?

Please see this tutorial on how to clone and resize: How to increase disk space on existing AWS EC2 Linux (Ubuntu) Instance without losing data

Hope that helps.

若无相欠,怎会相见 2024-10-04 14:37:12

这是简单的方法...

假设您使用的是 Linux AMI,在您的情况下,您有一个简单的方法来增加文件系统的大小:

1) 停止实例
2) 分离根卷
3) 快照卷
4) 使用新大小从快照创建新卷
5) 将新卷附加到实例中原始卷所在的位置
6) 启动实例,停止除ssh之外的所有服务,并将根文件系统设置为只读
7) 扩大文件系统(例如使用 resize2fs)和/或分区(如果需要)
8) 重新启动

作为替代方案,您还可以启动一个新实例并映射实例存储,或者您可以结合前面的两个步骤创建一个新的 ami。

Here is the simple way...

Assuming that you are using a linux AMI, in your case you have an easy method for increasing the size of the file system:

1) Stop the instance
2) Detach the root volume
3) Snapshot the volume
4) Create a new volume from the snapshot using the new size
5) Attach the new volume to the instance on the same place where the original one was
6) Start the instance, stop all services except ssh and set the root filesystem read only
7) Enlarge the filesystem (using for example resize2fs) and or the partition if needed
8) Reboot

As an alternative you can also launch a new instance and map the instance storage or you can create a new ami combining the two previous steps.

沩ん囻菔务 2024-10-04 14:37:12

仅重新启动实例就解决了我的问题

之前:

/dev/xvda1       8256952 7837552         0 100% /
udev              299044       8    299036   1% /dev
tmpfs             121892     164    121728   1% /run
none                5120       0      5120   0% /run/lock
none              304724       0    304724   0% /run/shm

现在

/dev/xvda18256952 1062780   6774744  14% /
udev              299044       8    299036   1% /dev
tmpfs             121892     160    121732   1% /run
none                5120       0      5120   0% /run/lock
none              304724       0    304724   0% /run/shm

Only Rebooting the instance solved my problem

Earlier:

/dev/xvda1       8256952 7837552         0 100% /
udev              299044       8    299036   1% /dev
tmpfs             121892     164    121728   1% /run
none                5120       0      5120   0% /run/lock
none              304724       0    304724   0% /run/shm

Now

/dev/xvda18256952 1062780   6774744  14% /
udev              299044       8    299036   1% /dev
tmpfs             121892     160    121732   1% /run
none                5120       0      5120   0% /run/lock
none              304724       0    304724   0% /run/shm
梦醒时光 2024-10-04 14:37:12

默认情况下,剩余空间安装在 /mnt。

The remaining of your space is mounted by default at /mnt.

能怎样 2024-10-04 14:37:12

这是因为,“增加EBS卷的大小后,必须使用文件系统特定的命令将文件系统扩展到更大的大小。卷进入优化状态后,您可以立即调整文件系统的大小。” ,退回实例。

我今天遇到了同样的问题,我能够解决它,

  1. 找出你的文件系统的类型,
    $ cat /etc/fstab

  2. 遵循此 AWS 文档,该文档准确记录了调整 EC2 实例卷大小后扩展 Linux 分区/FS 的步骤。

    调整大小后扩展 Linux 文件系统卷

It is because, "After you increase the size of an EBS volume, you must use file system–specific commands to extend the file system to the larger size. You can resize the file system as soon as the volume enters the optimizing state.", without bouncing an instance.

I was just facing the same issue today, I was able to resolve it,

  1. Figure out the type of your file system,
    $ cat /etc/fstab

  2. Follow this AWS doc, that precisely documents the steps to extend the linux Partition/FS after resizing a volume of a EC2 instance.

    Extending a Linux File System After Resizing a Volume

小…红帽 2024-10-04 14:37:12

在 Ubuntu 上,用于扩展文件系统。

要查找块设备:

blkid

在我的例子中,类型是 TYPE="ext4"。

要调整磁盘卷大小:

sudo resize2fs /dev/xvdf

On Ubuntu, for Extend the Filesystem.

To find block device:

blkid

In my case type is TYPE="ext4".

To resize the disk volume:

sudo resize2fs /dev/xvdf
十秒萌定你 2024-10-04 14:37:12

以下是我解决与使用 EBS 磁盘空间增加 EC2 空间相关的问题的方法

使用 EC2 控制台扩展 EBS 卷

  1. 打开 EC2 控制台。

  2. 在导航窗格中,选择“实例”,然后
    然后选择您的实例。

  3. 选择“存储”选项卡,然后选择
    你的音量。

  4. 在“卷”窗格中,选中“卷”复选框
    您想要扩展的卷。

  5. 从“操作”中,选择“修改音量”。

  6. 在卷详细信息下,根据卷类型输入大小和 IOPS。

  7. 选择“修改”,然后在对话框中选择“修改”。


  8. 卷窗格,在卷下查看卷的优化进度
    状态。刷新卷窗格以查看进度更新。

现在,EC2 显示磁盘空间的更改,但通过 ssh 登录终端时,更改可能不会反映。

请按照以下步骤解决此问题:

[ec2-user ~]$ sudo lsblk
NAME          MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
nvme1n1       259:0    0  30G  0 disk /data
nvme0n1       259:1    0  16G  0 disk
└─nvme0n1p1   259:2    0   8G  0 part /
└─nvme0n1p128 259:3    0   1M  0 part

在上面的输出中,根卷 (nvme0n1) 有两个分区(nvme0n1p1 和 nvme0n1p128),而附加卷 (nvme1n1) 没有分区。 30G与ec2控制台中显示的空间相同。

现在,扩展分区。使用growpart命令并指定设备名称和分区号。

分区号是p后面的数字。例如,对于 nvme0n1p1,分区编号为 1。对于 nvme0n1p128,分区编号为 128。

要扩展名为 nvme0n1p1 的分区,请使用以下命令。

 [ec2-user ~]$ sudo growpart /dev/nvme0n1 1

验证分区是否已扩展。使用 lsblk 命令。分区大小现在应该等于卷大小。

[ec2-user ~]$ sudo lsblk
NAME          MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
nvme1n1       259:0    0  30G  0 disk /data
nvme0n1       259:1    0  16G  0 disk
└─nvme0n1p1   259:2    0  16G  0 part /
└─nvme0n1p128 259:3    0   1M  0 part

现在扩展文件系统。

一个。获取需要扩展的文件系统的名称、大小、类型和安装点。使用df -hT命令。

[ec2-user ~]$ df -hT
Filesystem      Type  Size  Used Avail Use% Mounted on
/dev/nvme0n1p1  xfs   8.0G  1.6G  6.5G  20% /
/dev/nvme1n1    xfs   8.0G   33M  8.0G   1% /data
...

b.扩展文件系统的命令因文件系统类型而异。根据您在上一步中记下的文件系统类型,选择以下正确的命令。

我。 [XFS 文件系统] 使用 xfs_growfs 命令并指定您在上一步中记下的文件系统的安装点。

例如,要扩展安装在 / 上的文件系统,请使用以下命令。

 [ec2-user ~]$ sudo xfs_growfs -d /

二. [Ext4 文件系统] 使用resize2fs 命令并指定您在上一步中记下的文件系统的名称。

例如,要扩展安装的名为 /dev/nvme0n1p1 的文件系统,请使用以下命令。

[ec2-user ~]$ sudo resize2fs /dev/nvme0n1p1

c.最后,验证文件系统是否已扩展。使用df -hT命令并确认文件系统大小等于卷大小。

Here is how I resolved the issue relating to increasing the EC2 space with the EBS disk space

Use the EC2 console to expand the EBS volume

  1. Open the EC2 console.

  2. In the navigation pane, choose Instances, and
    then select your instance.

  3. Choose the Storage tab, and then select
    your volume.

  4. In the Volumes pane, select the check box for the
    volume you want to expand.

  5. From Actions, choose Modify volume.

  6. Under Volume details, enter the Size and IOPS based on the volume type.

  7. Choose Modify, and then choose Modify in the dialog box.

  8. In the
    Volumes pane, see the volume's optimizing progress under Volume
    state. Refresh the Volumes pane to see progress updates.

Now, the EC2 shows the changes in the disk space but when logged into the terminal through the ssh, the changes might not reflect.

Follow these steps to resolve this:

[ec2-user ~]$ sudo lsblk
NAME          MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
nvme1n1       259:0    0  30G  0 disk /data
nvme0n1       259:1    0  16G  0 disk
└─nvme0n1p1   259:2    0   8G  0 part /
└─nvme0n1p128 259:3    0   1M  0 part

In the above output, the root volume (nvme0n1) has two partitions (nvme0n1p1 and nvme0n1p128), while the additional volume (nvme1n1) has no partitions. The 30G is the same as what the space is showing in the ec2 console.

Now, extend the partition. Use the growpart command and specify the device name and the partition number.

The partition number is the number after the p. For example, for nvme0n1p1, the partition number is 1. For nvme0n1p128, the partition number is 128.

To extend a partition named nvme0n1p1, use the following command.

 [ec2-user ~]$ sudo growpart /dev/nvme0n1 1

Verify that the partition has been extended. Use the lsblk command. The partition size should now be equal to the volume size.

[ec2-user ~]$ sudo lsblk
NAME          MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
nvme1n1       259:0    0  30G  0 disk /data
nvme0n1       259:1    0  16G  0 disk
└─nvme0n1p1   259:2    0  16G  0 part /
└─nvme0n1p128 259:3    0   1M  0 part

Now Extend the file system.

a. Get the name, size, type, and mount point for the file system that you need to extend. Use the df -hT command.

[ec2-user ~]$ df -hT
Filesystem      Type  Size  Used Avail Use% Mounted on
/dev/nvme0n1p1  xfs   8.0G  1.6G  6.5G  20% /
/dev/nvme1n1    xfs   8.0G   33M  8.0G   1% /data
...

b. The commands to extend the file system differ depending on the file system type. Choose the following correct command based on the file system type that you noted in the previous step.

i. [XFS file system] Use the xfs_growfs command and specify the mount point of the file system that you noted in the previous step.

For example, to extend a file system mounted on /, use the following command.

 [ec2-user ~]$ sudo xfs_growfs -d /

ii. [Ext4 file system] Use the resize2fs command and specify the name of the file system that you noted in the previous step.

For example, to extend a file system mounted named /dev/nvme0n1p1, use the following command.

[ec2-user ~]$ sudo resize2fs /dev/nvme0n1p1

c. Finally, verify that the file system has been extended. Use the df -hT command and confirm that the file system size is equal to the volume size.

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