1.查看当前是否已有 Swap
free -h2.创建 Swap 文件
以创建一个 2G 的 Swap 文件为例(可改成 1G、4G 等):
fallocate -l 2G /swapfile3.设置权限
这步非常重要,必须设置权限,否则无法生效
chmod 600 /swapfile
4.格式化为 Swap
mkswap /swapfile
5.启用 Swap
swapon /swapfile
查看是否启用成功
free -h6.开机自动挂载
- 编辑
/etc/fstab:
nano /etc/fstab- 在文件末尾添加:
/swapfile none swap sw 0 0- 按
Ctrl + X保存退出
暂无评论