31

i created my EC2 Machine using Community Image of Centos 6.3 x64. i have added a 35 GB disk. Now when i do #df -h

Filesystem            Size  Used Avail Use% Mounted on
/dev/xvda1            7.9G  1.2G  6.4G  16% /
tmpfs                 7.3G     0  7.3G   0% /dev/shm

my disk is 35GB but its showing 8 GB in root and 7 as tmpfs.

i tried to use resize2fs but it didnt work on centos. disk has ext4 partation..

# resize2fs /dev/xvda
resize2fs 1.41.12 (17-May-2010)
resize2fs: Device or resource busy while trying to open /dev/xvda
Couldn't find valid filesystem superblock.

or even if i tried resize2fs /dev/xvda1 it says device has nothing to do.

any idea or other way, its my root disk(/). so cant unmount it.

4

5 回答 5

41

我找到了一种方法,如果不确定原因,resize2fs 不起作用,但它说设备或资源忙。我发现了一篇关于resizedisk using fdisk的非常好的文章,我们可以通过删除和创建它来增加块大小并使分区可启动。它所需要的只是重新启动。如果您使用相同的启动气缸,它不会影响您的数据。

# 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: Device or resource busy.
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)
The filesystem is already 5242624 blocks long.  Nothing to do!
于 2014-06-04T06:55:26.103 回答
30

以下步骤非常简单,对我来说效果很好:

# lsblk
NAME    MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda    202:0    0  30G  0 disk 
└─xvda1 202:1    0   8G  0 part /

以 root 身份执行以下命令:

# yum install cloud-utils-growpart

# growpart /dev/xvda 1

# reboot

重启后:

# lsblk
NAME    MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda    202:0    0  30G  0 disk 
└─xvda1 202:1    0  30G  0 part /
于 2016-07-19T16:11:50.203 回答
9

我遇到了同样的问题。我需要做的就是

  1. 重启实例
  2. 运行命令

    sudo resize2fs -f /dev/xxxx
    

它对我很有效。

于 2016-11-15T11:19:51.323 回答
3

Adeel Ahmad 答案的补充:

如果您尝试从具有交换分区的 AMI 启动实例,则必须执行其他步骤。

例如,如果 ami 包含以下内容:

# fdisk -l
Disk /dev/xvde: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 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: 0xe211223f

    Device Boot      Start         End      Blocks   Id  System
/dev/xvde1   *           1        1291    10369926   83  Linux
/dev/xvde2            1292        1305      112455   82  Linux swap / Solaris

如果我必须将容量升级到 20GB,我将创建一个 AMI 并尝试启动另一个具有 20GB 空间的实例。在此之后,如果我尝试上述步骤,磁盘空间不会增加,因为在 xvde1 和新空间之间有一个 xvde2 分区。

$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/xvde1            9.8G  7.5G  1.8G  81% /

$ fdisk -l

Disk /dev/xvde: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0xe211223f

    Device Boot      Start         End      Blocks   Id  System
/dev/xvde1   *           1        1291    10369926   83  Linux
/dev/xvde2            1292        1305      112455   82  Linux swap / Solaris

$ resize2fs /dev/xvde1 
resize2fs 1.41.12 (17-May-2010)
The filesystem is already 2592481 blocks long.  Nothing to do!

在这种情况下,请执行以下操作

  1. 删除两个分区
  2. 使用新的所需大小减去交换空间的大小创建新的主分区
  3. 为此分区添加可引导标志
  4. 创建第二个分区
  5. 将其标记为交换
  6. 写入更改并重新启动
  7. 扩展分区 1
  8. 设置交换或

删除分区 1 选定的分区 1

Command (m for help): d  <<6>>
Partition number (1-4): 1 <<6.0.1>> 

删除分区 2 选定的分区 2

Command (m for help): d  <<6.2>>

创建调整大小的主分区 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):<<NEW_UPPER_LIMIT>> <<11>>

TAKE CARE : 2048 应该替换为您原来的起始扇区,否则系统将无法启动。NEW_UPPER_LIMIT 将是上限的新扇区号,其余的将留作交换。为了保持相同的交换空间,减去原始的开始和结束扇区号,然后从 41943039(或您的上限)中减去结果

创建交换分区

Command (m for help): n  <<12>>
Command action    
e   extended    
p   primary partition (1-4) 
p  <<13>>
Partition number (1-4): 2  <<14>> 
First sector (<<NEW_UPPER_LIMIT+1>>-41943039, default <<NEW_UPPER_LIMIT+1>>): <<USE_DEFAULT>>  <<15>> 
Last sector, +sectors or +size{K,M,G}(<<NEW_UPPER_LIMIT+1>>-41943039,default 41943039):<<USE_DEFAULT>> <<16>>
Using default value 41943039

为分区 1 添加可引导位

Command (m for help): a  <<17>>
Partition number (1-4): 1  <<18>>

将分区 2 标记为交换

Command (m for help): l <<19>>

现在您将看到一个文件系统列表。注意对应于 Linux 交换的那个(比如 82)

Command (m for help): t <<20>>
Partition number (1-4): 2 <<21>>
Hex Code (type l to list codes) : 82 <<22>>

写入更改并重新启动

Command (m for help): w  <<23>> The partition table has been altered!
....

$ sudo reboot

重启后运行

resize2fs /dev/xvde1

这将调整你的 fs

现在使用第二个分区作为交换

$ mkswap /dev/<<SECOND SWAP PARTITION(run fdisk -l to get the name)>>
$ swapon /dev/<<SECOND SWAP PARTITION(run fdisk -l to get the name)>>

您可以检查 /proc/swaps 文件以验证

$ cat /proc/swaps

现在将以下内容添加到 /etc/fstab 以使这些更改保持不变

在 /etc/fstab 末尾(使用 nano 或 vi 等打开)

/dev/<<SECOND SWAP PARTITION>>   swap    swap   defaults   0 0

保存并退出

重启并检查

于 2015-03-04T13:51:56.123 回答
0

我的 Debian 8 ec2 实例遇到了同样的问题并且出现了错误

FAILED: failed to get CHS from /dev/xvda

解决方案

$ sudo parted /dev/xvda resizepart 1
Warning: Partition /dev/xvda1 is being used. Are you sure you want to continue?
Yes/No? yes                                                             
End?  [8588MB]? 100                  
$ sudo resize2fs /dev/xvda1
$ lsblk
$ df -h 

你会看到现在 ebs 的音量增加了。

于 2019-11-05T07:22:48.377 回答