2021-06-21 04:11:41 +08:00
|
|
|
|
#!/usr/bin/env bash
|
2021-06-21 05:22:02 +08:00
|
|
|
|
echo "
|
2021-06-21 05:35:35 +08:00
|
|
|
|
Creat-SWAP by yanglc
|
|
|
|
|
本脚本仅在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:35:35 +08:00
|
|
|
|
echo "按任意键添加1G大小的SWAP分区:"
|
2021-06-21 04:11:41 +08:00
|
|
|
|
char=`get_char`
|
2021-06-21 05:35:35 +08:00
|
|
|
|
echo "###########开始添加SWAP分区##########"
|
2021-06-21 05:22:02 +08:00
|
|
|
|
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:35:35 +08:00
|
|
|
|
echo " ###########设置交换分区文件##########"
|
2021-06-21 04:11:41 +08:00
|
|
|
|
mkswap /mnt/swap
|
|
|
|
|
echo -e
|
2021-06-21 05:35:35 +08:00
|
|
|
|
echo " ###########启动SWAP分区中...#########"
|
2021-06-21 05:22:02 +08:00
|
|
|
|
swapon /mnt/swap
|
|
|
|
|
echo -e
|
2021-06-21 05:35:35 +08:00
|
|
|
|
echo " ###########设置开机自启动############"
|
2021-06-21 04:11:41 +08:00
|
|
|
|
echo '/mnt/swap swap swap defaults 0 0' >> /etc/fstab
|
2021-06-21 05:35:35 +08:00
|
|
|
|
echo "All done!Thanks for using this shell script"
|