31

Centos 6.3 x64 のコミュニティ イメージを使用して EC2 マシンを作成しました。35 GB のディスクを追加しました。#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

私のディスクは 35GB ですが、root で 8 GB、tmpfs で 7 GB と表示されています。

resize2fs を使用しようとしましたが、centos では機能しませんでした。ディスクにはext4パーティションがあります..

# 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.

または、 resize2fs /dev/xvda1 を試しても、デバイスには何も関係がないと表示されます。

任意のアイデアまたはその他の方法で、それが私のルート ディスク (/) です。そのため、アンマウントできません。

4

5 に答える 5

41

理由がわからない場合にresize2fsが機能しないが、デバイスまたはリソースがビジーであると表示される方法を見つけました。fdisk を使用したresizediskに関する非常に優れた記事を見つけました。ブロック サイズを削除して作成し、パーティションを起動可能にすることでブロック サイズを増やすことができます。必要なのは再起動だけです。同じ開始シリンダーを使用しても、データには影響しません。

# 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

容量を 20 GB にアップグレードする必要がある場合は、AMI を作成し、20 GB のスペースで別のインスタンスを起動しようとします。この後、上記の手順を試しても、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. 2 番目のパーティションを作成する
  5. スワップとしてマークする
  6. 変更を書き込んで再起動する
  7. パーティション 1 を拡張する
  8. セットアップ スワップ OR

パーティション 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のサイズが変更されます

次に、2 番目のパーティションをスワップとして使用します

$ 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 に答える