How to add a Swap file

Sometimes it is necessary to add more swap space after installation. For example, you may upgrade the amount of RAM in your system. It might be advantageous to increase the amount of swap space if you perform memory-intense operations or run applications that require a large amount of memory.
You have two options: add a swap partition or add a swap file. It is recommended that you add a swap partition, but sometimes that is not easy if you do not have any free space available.

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=1024000

in the count type the amount of space you wont for your swap file. For example, 1024000=1GB

Setup the swap file with the command:
# mkswap /swapfile

To enable the swap file immediately but not automatically at boot
# swapon /swapfile
Or use # swapoff /swapfile to disable the mount.

To enable it at boot time, edit /etc/fstab to include:
# vi /etc/fstab
/swapfile               swap                    swap    defaults        0 0

The next time the system boots, it will enable the new swap file.
After adding the new swap file and enabling it, make sure it is enabled by viewing the output of the command
# cat /proc/swaps
or
# free

No comments:

Post a Comment