pdf-icon

增加虚拟内存说明

  1. 创建 swap 文件
fallocate -l 2G /swapfile
  1. 设置权限并格式化为 swap
chmod 600 /swapfile
mkswap /swapfile
  1. 启用 swap
swapon /swapfile
swapon --show
free -h
  1. 添加自动挂载服务
tee /etc/systemd/system/enable-swapfile.service >/dev/null <<'EOF'
[Unit]
Description=Enable swapfile via swapon
After=local-fs.target
Requires=local-fs.target

[Service]
Type=oneshot
ExecStart=/sbin/swapon /swapfile
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target
EOF
  1. 设置开机自自启
systemctl daemon-reload
systemctl enable enable-swapfile.service
On This Page