Add swap file in CentOS 6.4
Swapon command with option -s, displays the current swap space in KB.
# swapon -s
If a file with the name /extraswap already exists, check it with ‘ls’ command and delete it using ‘rm’ command.
# ls /extraswap # rm -rf /extraswap
The following dd command example creates a swap file with the name “extraswap” under / directory with a size of 1024MB (1GB).
# dd if=/dev/zero of=/extraswap bs=1M count=1024
Change the permission of the swap file so that only root can access it.
# chmod 600 /extraswap
Make this file as a swap file using mkswap command.
# mkswap /extraswap
Enable the newly created swapfile.
# swapon /extraswap
To make this swap file available as a swap area even after the reboot, add the following line to the /etc/fstab file.
/extraswap swap swap defaults 0 0
Verify whether the newly created swap area is available for your use.
# swapon -s