Ubuntu增加SWAP大小

1. 验证环境

妙算manifold2

Ubuntu20.04

2. 步骤

2.1 增加SWAP

 ​
 # 查看当前SWAP大小
 ​
 free -m
 ​
 #创建SWAP文件
 ​
 mkdir /swap
 ​
 cd /swap
 ​
 sudo dd if=/dev/zero of=swapfile bs=1024 count=2000000 # 2000000代表2G
 ​
 sudo mkswap -f swapfile
 ​
 # 激活SWAP
 ​
 sudo swapon swapfile
 ​
 # 再次查看 free -m 的结果
 ​
 free -m
 ​

2.2 将设定写入/etc/fstab

 ​
 # 如果文本中原先有swap相关语句,可尝试注释掉
 ​
 /swap/swapfile /swap swap defaults 0 0
 ​

2.3 如果只运行上两步重启后SWAP扩展失效

在/etc/rc.local中添加开启swap的命令

 ​
 # 添加在exit 0 之前
 ​
 swapon /data/swapfile
 ​

2.4 解决Ubuntu16.10后没有rc.local文件

自己创建一个

 ​
 sudo gedit //etc/rc.local
 ​

内容如下:

 ​
 #!/bin/sh -e
 #
 # rc.local
 #
 # This script is executed at the end of each multiuser runlevel.
 # Make sure that the script will "exit 0" on success or any other
 # value on error.
 #
 # In order to enable or disable this script just change the execution
 # bits.
 #
 # By default this script does nothing.
 ​
 exit 0

执行以下命令确保设置成功

 ​
 sudo chown root:root /etc/rc.local
 ​
 sudo chmod 755 /etc/rc.local
 ​
 sudo systemctl enable rc-local.service
 ​

————————————————

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值