最新消息:推荐好友购买联系客服领现金红包~

如何新建Swap交换分区

系统配置 主机帮助 411浏览

查看内存使用情况Swap,看下面Swap都为0

12># free -m
total used free shared buffers cached
Mem: 15948 15729 218 0 244 6123
-/+ buffers/cache: 9361 6586
Swap: 0 0 0

创建1个8G的文件

dd if=/dev/zero of=8g bs=10M count=800

将文件作为swap之用

14># mkswap /data/8g
mkswap: /data/8g: warning: don’t erase bootbits sectors
on whole disk. Use -f to force.
Setting up swapspace version 1, size = 8191996 KiB
no label, UUID=z35e6daf-7ede-8bm2-b4da-dbcb50392745

启用新建的swap

swapon /data/8g

再查看就有swap了

16># free -m
total used free shared buffers cached
Mem: 15948 15729 218 0 244 6123
-/+ buffers/cache: 9361 6586
Swap: 7999 0 7999

设置为自动启用,最后一行加入命令

17># vim /etc/rc.local

#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don’t
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local
swapon /data/8g

转载请注明:主机帮助 » 如何新建Swap交换分区