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

opensshにてfingerprint確認を省略する設定

[pukiwiki] // tag // ssh openssh // fingerprint // Are you sure you want to continue connecting // k …

no image

Open Jtalkを入れてみたのでインストール・環境設定をメモ書き

会社の開発チームから、”音声合成ツールのOpen Jtalkを試したいので、開発サーバーに入れといてくださ~い”との依頼を受けたので、ひとまず動かせるところまでざざっと調べてイ …

no image

[メモ]WindowsサーバのフォルダをLinuxサーバーへマウント

[pukiwiki] しばらくsmbを使っていなかったので、いつの間にかsmbmountを使わずとも mountコマンドのオプションでマウントを出来ることを知らなかったw WindowsフォルダのLi …

no image

postfixadminでのメールサーバー構築

会社のメールサーバーの再構築のための検証として、いろいろと。 参考サイト お世話になっています! AIT:postfixadminのインストール Postfix+MySQL+Postfix Admin …

nagios core​/1.インストール

  [pukiwiki] ものすっごい久しぶり、5年ぶりくらいに環境をセットアップしたので一応メモ。 インストールおよび初期設定までの作業ログ。 コンフィグの書式とかはなんとなく覚えてるけど、どれが何 …

宅麺