​http://inthirties.com:90/thread-1228-1-1.html​

 

一、分区方式
1.创建swap分区,例如:
# fdisk /dev/sdb
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-13054, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-13054, default 13054): +100M
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 82
Changed system type of partition 1 to 82 (Linux swap / Solaris)
Command (m for help): w
The partition table has been altered!
2. 同步分区表
# partprobe
3.设置交换区
# mkswap /dev/sdb1
4.编辑/etc/fstab文件
添加如下内容:
/dev/sdb1 swap swap defaults 0 0
5.启用swap 分区
# swapon -a
6.验证swap分区是否启用
# swapon -s
Filename Type Size Used Priority
/dev/sdb1 partition 104380 0 -2
二、文件方式
1.创建文件
# dd if=/dev/zero of=/swapfile bs=1024 count=100
2. 查看文件属性
# ls -lh /swapfile
-rw-r--r-- 1 root root 100K Apr 24 16:54 /swapfile
3. 设置swap
# mkswap /swapfile
4.编辑/etc/fstab文件
添加如下内容:
/swapfile swap swap defaults 0 0
5. 启用swap
# swapon /swapfile
6.验证swap是否启用
# swapon -s
Filename Type Size Used Priority
/swapfile file 92 0 -3