[root@server103 ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda2 20G 6.5G 12G 35% /
/dev/sda5 20G 4.1G 15G 23% /home
/dev/sda1 99M 12M 83M 13% /boot
/dev/sda6 205G 99G 96G 51% /data
tmpfs 1.5G 0 1.5G 0% /dev/shm
[root@server103 ~]# free -m
total used free shared buffers cached
Mem: 3018 2626 391 0 83 1689
-/+ buffers/cache: 853 2164
Swap: 2047 65 1981
[root@server103 ~]# dd if=/dev/zero of=/swapfile bs=1024 count=4048000
4048000+0 records in
4048000+0 records out
4145152000 bytes (4.1 GB) copied, 313.925 seconds, 13.2 MB/s
[root@server103 ~]# mkswap /swapfile
Setting up swapspace version 1, size = 4145147 kB
[root@server103 ~]# free -m
total used free shared buffers cached
Mem: 3018 2991 26 0 4 2099
-/+ buffers/cache: 887 2131
Swap: 2047 146 1900
[root@server103 ~]# swapon /swapfile
[root@server103 ~]# free -m
total used free shared buffers cached
Mem: 3018 2998 19 0 5 2101
-/+ buffers/cache: 891 2127
Swap: 6000 146 5853
[root@server103 ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda2 20G 11G 8.1G 56% /
/dev/sda5 20G 4.1G 15G 23% /home
/dev/sda1 99M 12M 83M 13% /boot
/dev/sda6 205G 99G 96G 51% /data
tmpfs 1.5G 0 1.5G 0% /dev/shm
最后就是vi /etc/fstab
/swapfile swap swap defaults 0 0