1.查看SWAP
[root@192 oc]# cat /proc/swaps
Filename Type Size Used Priority
/dev/sda3 partition 8024 104 -1
[root@192 oc]#
2.通过DD创建文件
dd if=/dev/zero of=/swapfile bs=512 count=4000000
dd if=/dev/zero of=/swapfile bs=512 count=8000000
2000000+0 records in
2000000+0 records out
1024000000 bytes (1.0 GB) copied, 23.4213 seconds, 43.7 MB/s
[root@192 oc]#
[root@192 oc]# ll
总计 1001012
drwx------ 2 root root 16384 06-03 06:56 lost+found
-rw-r--r-- 1 root root 1024000000 06-12 10:24 swap
drwxr-xr-x 4 root root 4096 06-08 16:15 tmp
[root@192 oc]#
3.转化为swap格式
[root@backoffice01 ~]# mkswap /swapfile
mkswap: /swapfile: warning: don't erase bootbits sectors
on whole disk. Use -f to force.
Setting up swapspace version 1, size = 1999996 KiB
no label, UUID=92896c21-e21b-4e16-b5de-9319931b31ac
[root@192 oc]# free
total used free shared buffers cached
Mem: 1035108 1018168 16940 0 14716 892500
-/+ buffers/cache: 110952 924156
Swap: 8024 104 7920
[root@192 oc]#
启用,加入到swap池中。
[root@192 oc]# swapon /swapfile
[root@192 oc]# free
total used free shared buffers cached
Mem: 1035108 1018228 16880 0 14748 892592
-/+ buffers/cache: 110888 924220
Swap: 1008016 104 1007912
[root@192 oc]#
[root@192 oc]# cat /proc/swaps
Filename Type Size Used Priority
/dev/sda3 partition 8024 104 -1
/oc/swap file 999992 0 -4
[root@192 oc]#
从swap池中拿掉
[root@192 oc]# swapoff /oc/swap
[root@192 oc]# free
total used free shared buffers cached
Mem: 1035108 1018780 16328 0 15096 892760
-/+ buffers/cache: 110924 924184
Swap: 8024 104 7920
[root@192 oc]# cat /proc/swaps
Filename Type Size Used Priority
/dev/sda3 partition 8024 104 -1
[root@192 oc]#
开机自动启动:
/swapfile swap swap defaults 0 0
另:
将整个设备划为swap分区
fdisk时代码为82 linux swap,
分区后:
# mkswap /dev/sdc3
# swapon /dev/sdc3