我用的CentOS, 直接贴操作步骤,供参考:
[root@1pad ~]# free -m
total used free shared buffers cachedMem: 3702 722 2979 0 149 230
-/+ buffers/cache: 342 3359
Swap: 3839 0 3839
[root@1pad ~]# cd /home
[root@1pad home]# pwd
/home
[root@1pad home]# dd if=/dev/zero of=swapfile bs=4096 count=15728640 #(新的虚拟内存大小 = bs * count bytes)
15728640+0 records in
15728640+0 records out
64424509440 bytes (64 GB) copied, 478.958 s, 135 MB/s
[root@1pad home]# ls
alex swapfile
[root@1pad home]# /sbin/mkswap swapfile
mkswap: swapfile: warning: don't erase bootbits sectors
on whole disk. Use -f to force.
Setting up swapspace version 1, size = 62914556 KiB
no label, UUID=a029accb-6676-48cb-ba7d-d31b9e84be37
[root@1pad home]# /sbin/swapon swapfile
[root@1pad home]# /sbin/swapon -s
Filename Type Size Used Priority
/dev/dm-1 partition 3932152 236 -1
/home/swapfile file 62914552 0 -2
[root@1pad home]# free -m
total used free shared buffers cached
Mem: 3702 3565 137 0 138 2972
-/+ buffers/cache: 453 3248
Swap: 65279 0 65279
[root@1pad home]# vim /etc/fstab #在fstab结尾加入如下两行,目的是为了让新创建的swap分区在电脑重启后能够自动挂载
#Expand the swap space---Alex Tian, Jan. 27th, 2015
/home/swapfile swap swap defaults 0 0
最后检查/etc/rc.d/rc.local脚本中是否将所有fstab中要求挂载的swap分区都给关闭。
如果是的话,将其中的swapoff -a注释或者删掉。