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


関連記事

no image

[メモ]メモリ調査上での疑問

[pukiwiki] お客様のHP DL360 G5へのメモリ増設を調査する際、シングルランク、デュアルランクという明記が あったので、気になって調査。 **1)シングルランク、デュアルランクの違い …

no image

ssh ホストベース認証(メモ)

[pukiwiki] *概要 パスワード/パスフレーズなしでSSHログインできるよう、ホストベース認証を設定する方法。 **クライアント側(接続元)設定 ホストベースでの外部ホストへの接続を許可するた …

no image

LinkStation rootアカウントのリセットとtelnetログイン

職場のLinkStationが不調になったとの連絡があり、フォルダにアクセスできなくなったり、起動してしばらくするとエクスプローラーからの応答が無くなったり、管理画面へのアクセスもタイムアウトする始末 …

nagiosgraph​/3.グラフ設定追加

  [pukiwiki] *nagiosgraphへのグラフ設定追加 [#if03e7ea] nagiosgraphは監視対象のホストにプラグインを追加すると、プロセス再起動時に認識し 追加したプラグ …

no image

JDK+Tocmat+Tomcat-connectorのインストール

[pukiwiki] 【今回の環境】 OS CentOS4.* FrontEnd Httpd-2.0.52(RPM) JDK jdk-1.5.0_07-fcs Tomcat apache-tomcat …

宅麺