http://www.centos.org/docs/5/html/Deployment_Guide-en-US/s1-swap-adding.html
5.2.3. Creating a Swap File
To add a swap file:
-
Determine the size of the new swap file in megabytes and multiply by 1024 to determine the number of blocks. For example, the block size of a 64 MB swap file is 65536.
-
At a shell prompt as root, type the following command with count being equal to the desired block size:
dd if=/dev/zero of=/swapfile bs=1024 count=65536
-
dd if=/dev/zero of=/swapfile bs=1024 count=2048k #1G内存的OS
-
Setup the swap file with the command:
mkswap /swapfile
-
To enable the swap file immediately but not automatically at boot time:
swapon /swapfile
-
To enable it at boot time, edit /etc/fstab to include the following entry:
/swapfile swap swap defaults 0 0
The next time the system boots, it enables the new swap file.
1、检查 Swap 空间
在设置 Swap 文件之前,有必要先检查一下系统里有没有既存的 Swap 文件。
运行以下命令:
swapon -s
如果返回的信息概要是空的,则表示 Swap 文件不存在。
2、检查文件系统
在设置 Swap 文件之前,同样有必要检查一下文件系统,看看是否有足够的硬盘空间来设置 Swap 。运行以下命令:
df -hal
检查返回的信息,还剩余足够的硬盘空间即可。