create-swap/create-swap.sh

37 lines
1.0 KiB
Bash
Raw Normal View History

2021-06-21 04:11:41 +08:00
#!/usr/bin/env bash
2021-06-21 04:19:17 +08:00
RED_COLOR="\033[0;31m"
NO_COLOR="\033[0m"
GREEN="\033[32m\033[01m"
BLUE="\033[0;36m"
FUCHSIA="\033[0;35m"
2021-06-21 05:24:24 +08:00
echo "export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin:$PATH" >> ~/.bashrc
source ~/.bashrc
sleep 2
2021-06-21 05:22:02 +08:00
echo "
${GREEN} Creat-SWAP by yanglc
${GREEN} 本脚本仅在Debian系系统下进行过测试"
2021-06-21 04:11:41 +08:00
get_char()
{
SAVEDSTTY=`stty -g`
stty -echo
stty cbreak
dd if=/dev/tty bs=1 count=1 2> /dev/null
stty -raw
stty echo
stty $SAVEDSTTY
}
2021-06-21 05:22:02 +08:00
echo " ${GREEN} 按任意键添加1G大小的SWAP分区"
2021-06-21 04:11:41 +08:00
char=`get_char`
2021-06-21 05:22:02 +08:00
echo " ${GREEN} ###########开始添加SWAP分区##########"
dd if=/dev/zero of=/mnt/swap bs=1M count=1024
2021-06-21 04:11:41 +08:00
echo -e
2021-06-21 05:22:02 +08:00
echo " ${GREEN} ###########设置交换分区文件##########"
2021-06-21 04:11:41 +08:00
mkswap /mnt/swap
echo -e
2021-06-21 05:22:02 +08:00
echo " ${GREEN} ###########启动SWAP分区中...#########"
swapon /mnt/swap
echo -e
echo " ${GREEN} ###########设置开机自启动############"
2021-06-21 04:11:41 +08:00
echo '/mnt/swap swap swap defaults 0 0' >> /etc/fstab
2021-06-21 05:22:02 +08:00
echo " ${GREEN} All doneThanks for using this shell script"