Last active
March 19, 2017 17:34
-
-
Save chusiang/965fae2e3a8707792eb5 to your computer and use it in GitHub Desktop.
Enable swap with swapfile for Linux.
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 | |
# ============================================================ | |
# Author: 凍仁翔 / chusiang.lai (at) gmail.com | |
# Blog: http://note.drx.tw | |
# Filename: create-swapfile.sh | |
# Modified: 2015-04-22 09:50 | |
# Description: Enable swap with swapfile for Linux. | |
# Reference: | |
# 1. Linux Add a Swap File | nixCraft | |
# - http://www.cyberciti.biz/faq/linux-add-a-swap-file-howto/ | |
# =========================================================== | |
# Size of swapfile. | |
# | |
# 1G: 1048576 | |
# 2G: 2097152 | |
# 4G: 4194304 | |
# 8G: 8388608 | |
# 16G: 16777216 (not recommended) | |
# | |
SIZE="2097152" | |
# Create swapfile. | |
sudo dd if=/dev/zero of=/swapfile bs=1024 count=$SIZE | |
# Format swapfile. | |
sudo mkswap /swapfile | |
# Enable swap. | |
sudo swapon /swapfile | |
# Mount swap at boot. | |
sudo su -c "cat >> /etc/fstab << EOF | |
/swapfile none swap sw 0 0 | |
EOF" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment