Created
July 26, 2017 16:13
-
-
Save iitenkida7/5796cc38db3325943efdf5666748ca9e to your computer and use it in GitHub Desktop.
[bash]create_swap_file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#概要 AWSなどでは、swap領域が割り当てられていない。 | |
# Swapファイルを作成し、swaponする為のスクリプト。 | |
# 引数に swap容量を記載して、実行して下さい。 | |
# エラー処理指定ないので、注意して実行すること。 | |
# また、コマンド実行後、fstab に swapのmountを追加すること。 | |
# 例) create_swap_file 2048 | |
function create_swap_file(){ | |
echo "================================================================================" | |
free -m | |
echo "================================================================================" | |
mkdir -p /var/swap | |
dd if=/dev/zero of=/var/swap/swapfile bs=1M count=${1} && chmod 644 /var/swap/swapfile | |
mkswap /var/swap/swapfile && swapon /var/swap/swapfile | |
echo "================================================================================" | |
free -m | |
echo "================================================================================" | |
echo -en "Please add fstab \n/var/swap/swapfile swap swap defaults 0 0\n" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment