1)在linux下,首先,查看内存和swap大小:
[root@rhel6 usr]# free -m
Mem:
1386
1272
114
0
90
952
-/+ buffers/cache:
228
1158
Swap:
2047
0
2047
2)创建swap文件:
[root@rhel6 usr]# mkdir swap
[root@rhel6 usr]# cd swap/
[root@rhel6 swap]# dd if=/dev/zero of=swapfile bs=402400count=10000
记录了10000+0 的读入
记录了10000+0 的写出
4024000000字节(4.0 GB)已复制,224.925 秒,17.9 MB/秒
[root@rhel6 swap]# ls -al
总用量 3929700
drwxr-xr-x.
2 root root
4096 2月
410:16 .
drwxr-xr-x. 15 root root
4096 2月
4 10:15 ..
-rw-r--r--.
1 root root 4024000000 2月
4 10:20 swapfile
[root@rhel6 swap]# mkswap swapfile
mkswap: swapfile: warning: don't erase bootbits sectors
Setting up swapspace version 1, size = 3929680 KiB
no label, UUID=4e2ce2fe-3963-46ce-90cd-466495cd8ca8
3)激活swap文件:
[root@rhel6 swap]# swapon swapfile
[root@rhel6 swap]# free -m
Mem:
1386
1296
90
0
82
975
-/+ buffers/cache:
239
1147
Swap:
5885
0
5885
4)若想要开机时自启动,需要修改文件/etc/fstab中的swap行:
[root@rhel6 swap]# vi /etc/fstab
UUID=8c6bea6a-3bba-4594-b5a8-fd4afd311476 swap
swap
defaul
ts
0 0
/usr/swap/swapfile
swap
defaul
ts
0 0
jesus love you!