Help us understand the problem. What is going on with this article?

AmazonLinux2 でswap領域作成

More than 1 year has passed since last update.

Attach SWAP area to AmazonLinux2

自分用のメモです。

環境

% cat /etc/os-release
NAME="Amazon Linux"
VERSION="2"
ID="amzn"
ID_LIKE="centos rhel fedora"
VERSION_ID="2"
PRETTY_NAME="Amazon Linux 2"
ANSI_COLOR="0;33"
CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2"
HOME_URL="https://amazonlinux.com/"

手順

1Gバイトのスワップファイルを /swapfile において、Linuxのスワップ領域として利用します。

% sudo dd if=/dev/zero of=/swapfile bs=1M count=1024
% sudo chmod 600 /swapfile
% sudo mkswap /swapfile
% free
              total        used        free      shared  buff/cache   available
Mem:        1011064       91304       72464        3516      847296      746632
Swap:             0           0           0

# この時点でfreeしてもまだシステムに認識させてないので0ですよ^^;

% sudo swapon /swapfile
% free
              total        used        free      shared  buff/cache   available
Mem:        1011064       92348       70168        3516      848548      745592
Swap:       1048572           0     1048572

# 認識されました!!

という感じです。
あとは/etc/fstab に書いとけば再起動してもswap割当てられます。

/swapfile  swap        swap    defaults        0   0 # 追記

以上。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away