Last active
August 28, 2018 04:43
-
-
Save lawvs/b343853ddba8823445983bd55949fdad to your computer and use it in GitHub Desktop.
新建交换分区
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 | |
# set flag fast fail | |
set -e | |
if [[ $EUID -ne 0 ]]; then | |
echo "This script must be run as root" | |
exit 1 | |
fi | |
# dd if=/dev/zero of=目录/文件名 bs=容量 count=次数 | |
dd if=/dev/zero of=/swapfile bs=100M count=20 | |
# 生成交换分区文件 | |
mkswap /swapfile | |
# 修改文件权限 | |
# chown root:root /swapfile | |
chmod 0600 /swapfile | |
# 激活交换分区 | |
swapon /swapfile | |
swapon -s # 检查是否生效 | |
# 关闭交换分区 | |
# swapoff /swapfile | |
# 将/dev/sdc自动挂载成Swap写入fstab文件里 | |
echo /swapfile swap swap defaults 0 0 >> /etc/fstab | |
# 检查是否正确 | |
swapoff -a # disable all swaps from /proc/swaps | |
swapon -a # enable all swaps from /etc/fstab | |
echo 'Added swap complete!' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment