这几天Gullo小鸡做活动,买了个1.69刀的NAT小鸡儿,OpenVZ架构,但没有swap,我们添加一个,即便用不上也好看呀

vi /etc/profile.d/swap-plus.sh

按 i 编辑(添加512M swap为例)

#!/bin/bash
SWAP="${1:-512}"
NEW="$[SWAP*1024]"; TEMP="${NEW//?/ }"; OLD="${TEMP:1}0"
umount /proc/meminfo 2> /dev/null
sed "/^Swap\(Total\|Free\):/s,$OLD,$NEW," /proc/meminfo > /etc/fake_meminfo
mount --bind /etc/fake_meminfo /proc/meminfo

按esc结束编辑,按:w保存
授权 chmod +x /etc/profile.d/swap-plus.sh
随后reboot重启就可以了

重启后等一会儿,敲入 free -m 查看swap内存

感谢Locer@本人马保国提供思路

Last modification:November 24, 2023
If you think my article is useful to you, please feel free to appreciate