36

ubuntu 设置虚拟内存(增加swap),并且加入开机项,开机启动

 3 years ago
source link: https://blog.popkx.com/ubuntu-set-swap-and-make-it-run-automaticly-when-start/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

ubuntu 设置虚拟内存(增加swap),并且加入开机项,开机启动

发表于 2018-07-27 21:07:47   |   已被 访问: 578 次   |   分类于:   Linux笔记   |   暂无评论

ubuntu内存不够用时,可以通过增加 swap,设置虚拟内存分一部分磁盘当作内存使用,虽然没有直接使用内存那么快,但在速度要求不那么苛刻时也未尝不是一种解决方案,以下是我的一次具体添加过程:

进入 /var 目录,产生的 swapfile 放于此处

cd /var                       
dd if=/dev/zero of=swapfile bs=1M count=2048

制作 swapfile,并且开启 swap

mkswap swapfile 
swapon swapfile

然后将其加入开机启动项,方便系统重启后,自动加载 swap

echo ‘/var/swapfile swap swap defaults 0 0 ‘ >> /etc/fstab

但是,echo 语句似乎没有起作用,我重启系统后,swap并没有被自动加载。这条 echo 命令是我百度来的,菜鸟水平的我不管它为什么不可以,更重要的是实现开机自动加载。注意到 /etc/rc.local 文件中的命令会在系统开机的时候执行,于是在该文件里加入如下命令:

sudo swapon /var/swapfile

如下图所示:

重启后,发现 swap 自动加载了。

阅读更多:   Linux笔记


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK