当需要添加swap分区时,可以使用如下方法:
设置交换分区:
1 以dd指令建立swapoff
2 mkswap 来将swapfile 格式化为swap的档案格式。
3 swapon 来启动该系统文件,使之成为swap
[root@localhost ~]# dd if=/dev/zero f=/tmp/swap bs=4K count=16382
16382+0 records in
16382+0 records out
67100672 bytes (67 MB) copied, 1.05299 seconds, 63.7 MB/s
#mkswap 来将swapfile 格式化为swap的档案格式。
[root@localhost ~]# mkswap /tmp/swap
Setting up swapspace version 1, size = 67096 kB
[root@localhost ~]# free
total used free shared buffers cached
Mem: 473860 468516 5344 0 31996 328304
-/+ buffers/cache: 108216 365644
Swap: 1052216 0 1052216
#swapon 来启动该系统文件,使之成为swap
[root@localhost ~]# swapon /tmp/swap
[root@localhost ~]# free
total used free shared buffers cached
Mem: 473860 468516 5344 0 32020 328328
-/+ buffers/cache: 108168 365692
Swap: 1117736 0 1117736
使用bc来验证一下。
[root@localhost ~]# bc
bc 1.06
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
1117736-1052216
65520
4*16382
65528
quit
#swapoff 该文件并再次验证。
[root@localhost ~]# swapoff /tmp/swap
[root@localhost ~]# free
total used free shared buffers cached
Mem: 473860 468628 5232 0 32132 328776
-/+ buffers/cache: 107720 366140
Swap: 1052216 0 1052216