AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 414983
Accepted
Christian
Christian
Asked: 2012-08-08 00:59:02 +0800 CST2012-08-08 00:59:02 +0800 CST 2012-08-08 00:59:02 +0800 CST

EC2 驱动器不是 EBS 卷大小

  • 772

我有一个 EC2 实例,我为其创建了一个 500GB EBS 卷。不幸的是,EC2 实例显示只有 8GB 可用。

我只有一个驱动器,这是正确的。

[root@ip-10-244-134-250 ~]# ls -la /dev/x*
brw-rw---- 1 root disk 202, 1 Aug  7 08:54 /dev/xvda1

但是,那个驱动器只有 8GB

[root@ip-10-244-134-250 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/xvda1            8.0G  1.3G  6.7G  16% /
tmpfs                 3.7G     0  3.7G   0% /dev/shm

但是,fdisk 和 /proc/partitions 都显示正确的大小

[root@ip-10-244-134-250 ~]# fdisk -l

Disk /dev/xvda1: 536.9 GB, 536870912000 bytes
255 heads, 63 sectors/track, 65270 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/xvda1 doesn't contain a valid partition table

[root@ip-10-244-134-250 ~]# cat /proc/partitions 
major minor  #blocks  name

 202        1  524288000 xvda1

任何帮助将不胜感激,谢谢。

amazon-ec2
  • 4 4 个回答
  • 15557 Views

4 个回答

  • Voted
  1. Best Answer
    Eric Hammond
    2012-08-08T01:14:49+08:002012-08-08T01:14:49+08:00

    如果根文件系统是 ext3 或 ext4,则运行:

    sudo resize2fs /dev/xvda1
    

    如果根文件系统是 xfs(不太常见),则运行:

    sudo xfs_growfs /
    

    如果您以根用户身份登录,则可以省略“sudo”。

    这些命令应该在系统运行和文件系统挂载时运行。

    EBS 卷的标准是不包含分区表。EBS 卷通常被格式化为一个完整的文件系统,没有分区。

    • 35
  2. Neo
    2014-10-29T13:28:12+08:002014-10-29T13:28:12+08:00

    在专门为更改 EBS 卷大小的人重新调整大小之前,这里的答案似乎缺少几个步骤。如果您使用快照创建 EBS 或使用某些 AMI,您将需要扩展磁盘 (xvda)、扩展分区 (xvda1),然后扩展文件系统 (/)。

    如果我没看错的话,你的磁盘看起来是这样的:

    /dev/xvda
    |__/dev/xvda1__|______________ Free space______________|
    

    它需要看起来像这样:

    /dev/xvda
    |______________________/dev/xvda1______________________|
    

    之后,runningresize2fs将增长到 内的新空间xvda1,使用fdisk我们可以通过删除并再次创建它并使分区可启动来增加块大小。它所需要的只是重新启动。在大多数情况下,如果您使用相同的启动柱面,它不会影响您的数据,但请注意,重新创建分区时的任何错误都将导致丢失所有数据和/或服务器不会重新启动。 我建议将此作为新创建实例的第一步。否则拍摄您的 EC2 EBS 存储/等的快照。

    我在下面的块中用 <<#>> 标记了这些步骤,因此它们不是命令的一部分。您需要 root 权限,所以如果您不是 root,请执行“sudo sh”。

    <<1>> Look at the filesystem, it is 6G
    <<2>> Look at the disk and the partition, the disk is 21.5 GB but the partition is 6 GB (6291456 blocks)
    <<3>> Start fdisk for that disk (xvda, so not the partition xvda1)
    <<4>> Switch to sector display.
    <<5>> Print the partition(s), and remember the start sector (2048 in the example).
    <<6>> Delete the partition.
    <<7>> Create a new partition.
    <<8>> Make it primary.
    <<9>> First partition.
    <<10>> Enter the old start sector, do NOT make any typo here!!! (2048 in the example) 
    <<11>> Hit enter to accept the default (this is the remainder of the disk)
    <<12>> Print the changes and make sure the start sector is ok, if not restart at <<6>>
    <<13>> Make the partition bootable. do NOT forget this!!!
    <<14>> Enter your partition number (1 in the example)
    <<15>> Write the partition info back, this will end the fdisk session.
    <<16>> Reboot the server, and wait for it to come up (this may take longer than usual).
    <<17>> Verify the filesystem size.
    <<18>> If the filesystem is not around 20Gb as expected, you can use this command.
    
    
    # df -h  <<1>>
    
    Filesystem      Size  Used Avail Use% Mounted on
    /dev/xvda1      6.0G  2.0G  3.7G  35% / 
    tmpfs            15G     0   15G   0% /dev/shm
    
    # fdisk -l  <<2>>
    
    Disk /dev/xvda: 21.5 GB, 21474836480 bytes
    97 heads, 17 sectors/track, 25435 cylinders
    Units = cylinders of 1649 * 512 = 844288 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x0003b587
    
        Device Boot      Start         End      Blocks   Id  System
    /dev/xvda1   *           2        7632     6291456   83  Linux
    
    # fdisk /dev/xvda  <<3>>
    
    WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
             switch off the mode (command 'c') and change display units to
             sectors (command 'u').
    
    Command (m for help): u  <<4>>
    Changing display/entry units to sectors
    
    Command (m for help): p  <<5>>
    
    Disk /dev/xvda: 21.5 GB, 21474836480 bytes
    97 heads, 17 sectors/track, 25435 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: 0x0003b587
    
        Device Boot      Start         End      Blocks   Id  System
    /dev/xvda1   *        2048    12584959     6291456   83  Linux
    
    Command (m for help): d  <<6>>
    Selected partition 1
    
    Command (m for help): n  <<7>>
    Command action
       e   extended
       p   primary partition (1-4)
    p  <<8>>
    Partition number (1-4): 1  <<9>>
    First sector (17-41943039, default 17): 2048  <<10>>
    Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): <<11>>
    Using default value 41943039
    
    Command (m for help): p <<12>>
    
    Disk /dev/xvda: 21.5 GB, 21474836480 bytes
    97 heads, 17 sectors/track, 25435 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: 0x0003b587
    
        Device Boot      Start         End      Blocks   Id  System
    /dev/xvda1            2048    41943039    20970496   83  Linux
    
    Command (m for help): a  <<13>>
    Partition number (1-4): 1  <<14>>
    
    
    Command (m for help): w  <<15>>
    The partition table has been altered!
    
    Calling ioctl() to re-read partition table.
    
    WARNING: Re-reading the partition table failed with error 16: ...
    The kernel still uses the old table. The new table will be used at
    the next reboot or after you run partprobe(8) or kpartx(8)
    Syncing disks.
    
    # reboot  <<16>>
    
    <wait>
    
    # df -h  <<17>>
    Filesystem      Size  Used Avail Use% Mounted on
    /dev/xvda1       20G  2.0G   17G  11% / 
    tmpfs            15G     0   15G   0% /dev/shm
    
    # resize2fs /dev/xvda1  <<18>>
    resize2fs 1.41.12 (17-May-2010)
    Filesystem at /dev/xvda1 is mounted on /; on-line resizing required
    old desc_blocks = 1, new_desc_blocks = 2
    Performing an on-line resize of /dev/xvda1 to 5242624 (4k) blocks.
    The filesystem on /dev/xvda1 is now 5242624 blocks long.
    
    root@vs120 [~]#  df -h
    Filesystem      Size  Used Avail Use% Mounted on
    /dev/xvda1       20G  7.8G   11G  42% /
    tmpfs           498M     0  498M   0% /dev/shm
    /usr/tmpDSK     399M   11M  368M   3% /tmp
    root@vs120 [~]#
    
    • 13
  3. womble
    2012-08-08T01:02:02+08:002012-08-08T01:02:02+08:00

    调整 EBS 卷上文件系统的大小。如果您正在运行ext3(这通常是默认设置),您可以只运行e2resize /dev/xvda1.

    • 2
  4. David B
    2016-07-29T04:24:37+08:002016-07-29T04:24:37+08:00

    我使用从自定义 Ubuntu AMI 创建的实例尝试了@Neo 的答案。解释非常有帮助,但我需要将单元保持为块并跳过第 4 步。然后它完美地工作。

    还有一点是,在步骤#5 中,您必须复制起始块/柱面以在步骤#10 中使用。

    @Neo 的回答是如果你有一个分区的虚拟磁盘设备。如果您遇到此问题,您可以通过以下方式找到: lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT xvda 202:0 0 30G 0 disk └─xvda1 202:1 0 5G 0 part / xvda 和 xvda1 的大小非常不同。您可以调整 2fs 大小,这不会有任何区别,在我的例子中,xvda1 是 5G,这就是文件系统将使用的所有内容。

    谢谢,@Neo

    • 1

相关问题

  • 权限被拒绝(公钥)。从本地 Ubuntu 到 Amazon EC2 服务器的 SSH

  • 管理员如何管理他们的 EC2 EBS 和快照?

  • 云有多大?[关闭]

  • EC2 映像启动

  • 如何将安全组添加到正在运行的 EC2 实例?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve