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-28 00:14:58 +08:00
|
|
|
|
now=`free -m| grep "Swap:"| awk '{print $2}'`
|
|
|
|
|
echo "当前系统swap分区大小为:$now Mb"
|
|
|
|
|
echo "请输入要增加的swap分区大小(单位Mb):"
|
|
|
|
|
read -e swap
|
2021-06-21 05:35:35 +08:00
|
|
|
|
echo "###########开始添加SWAP分区##########"
|
2021-06-28 00:14:58 +08:00
|
|
|
|
sudo dd if=/dev/zero of=/mnt/swap bs=1M count=${swap}
|
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"
|