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!
この場合、次のようにします
- 両方のパーティションを削除します
- 新しい必要なサイズからスワップ領域のサイズを引いた新しいプライマリ パーティションを作成します。
- このパーティションの起動可能フラグを追加します
- 2 番目のパーティションを作成する
- スワップとしてマークする
- 変更を書き込んで再起動する
- パーティション 1 を拡張する
- セットアップ スワップ 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
保存して終了
再起動して確認