harumaki.net

インフラ屋の覚書や、ラーメン食べある記とか。

AWS CentOS GNU/Linux メモ

[AWS] EC2 HVMタイプを使う時のファイルシステム周りの作業2(swap追加)

投稿日:2015年10月16日

Last Updated on 2021年7月4日 by かんりにん

 
さしあたりAWSだから、t2インスタンスだから、というわけでは全くないけどメモ。

t2インスタンスは、もともとスワップ領域がないインスタンスタイプのため、スワップが必要な場合は、EBSを追加してmkswapでフォーマット、マウントして利用する。
インスタンスのローンチ時に”ステップ 4: ストレージの追加”であらかじめスワップ用のEBSボリュームを追加しておく。もちろん後からスワップ用EBSを追加してもOK。
今回はインスタンス作成時にswap用に追加したEBS”/dev/xvdb”をmkswapする。

1.swap用EBSボリュームをフォーマット

– fdisk実行

# fdisk /dev/xvdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x7625cfda.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
		
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
		
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').

– パーティション作成

今回はスワップ用として割り当てたEBSなのでシリンダーは最初から最後まで全部指定する。

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p					←基本パーティションを選択
Partition number (1-4): 1		←ナンバーを選択。デバイスは/dev/xvdb1となる。
First cylinder (1-261, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-261, default 261):
Using default value 261

– 書き込み

Command (m for help): w
The partition table has been altered!
		
Calling ioctl() to re-read partition table.
Syncing disks.

– パーティションを確認

# fdisk -l
		
Disk /dev/xvda: 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: 0x0002370f
		
    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *           1        1306    10484760   83  Linux
		
Disk /dev/xvdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 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: 0x7625cfda
		
    Device Boot      Start         End      Blocks   Id  System
/dev/xvdb1               1         261     2096451   83  Linux	←作成されていることを確認。

2.mkswap実行

# mkswap /dev/xvdb1
Setting up swapspace version 1, size = 2096444 KiB
no label, UUID=8262d073-5f98-422b-bb73-9705ef87b9e8

3.swapとしてマウント

# swapon /dev/xvdb1

4.swapしたボリュームの確認

# free
             total       used       free     shared    buffers     cached
Mem:       2052816     113960    1938856        152       5284      48560
-/+ buffers/cache:      60116    1992700
Swap:      2096444          0    2096444

5.fstabへ設定を追加

OS起動時にswapボリュームをマウントするよう、/etc/fstabへ設定を追加。
以下、追記内容の例。

/dev/xvdb1 none      swap    sw,pri=1        0 0

6.OS再起動後に再度チェック。

# free
             total       used       free     shared    buffers     cached
Mem:       2052816     112812    1940004        152       4580      46532
-/+ buffers/cache:      61700    1991116
Swap:      2096444          0    2096444

→/etc/fstabの設定も問題なし。これにて作業終了。
  

 

 

-AWS, CentOS, GNU/Linux, メモ
-,

執筆者:


comment

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA


関連記事

[AWS]s3putをかるく検証してみた

[pukiwiki] s3cmdにつづいて、s3putのテスト。 Amazon Linux AMIにはもともとec2-api-toolsなどのツールがインストール済みになっていて 環境設定をしなくて済 …

no image

net-snmp snmpd.logの設定を追加、変更

[pukiwiki] 某VPSサービスで借りた仮想サーバーでsnmpdを動かしたところ、ログがどこにも出ていなかったのでログ出力設定を追加。 たまたまだと思いつつ、設定状況は環境によって様々だと思うの …

no image

phpmyadminのインストール(rpm版)

[pukiwiki] ごく簡単だけど、備忘録として。 # yum install phpmyadmin RPMでインストールした場合、phpmyadminのコンテキストパス(?)は/usr/share …

[PHP] RedHat/CentOSのcurlで”SSL Connection Errorが発生しちゃった件

モバイルサイトのキャリア通信にて、ユーザー認証の部分でcurlを使っているが アプリサーバーのOSをCentOS5から6へ上げて検証していたところ、開発チームから“SSL Connecti …

no image

wordpressメモ、サイトのURLを変更する際のテーブル操作

職場でイントラ用に利用しているwordpressサイトを別サーバーに引っ越した際、サイトURLのメンテを忘れてしまい、後から手動で直すことに。 直す必要があるのは”WordPress アド …

宅麺