To add swap to linux machine:
1. Create a swap file. Size depends on your preference. Let's say we want to create a swap file with 8GB size (1024 x 1024 x 8 = 8388608).
# dd if=/dev/zero of=/swapfile bs=1024 count=8388608where if is source, of is output file for dd to write to which is /swapfile in this case, bs is read/write byte size at a time and count is number of blocks.
2. Once created, make it a swap file
# mkswap /swapfile3. Activate your swap file
# swapon /swapfile4. Check your newly created swap space using free or top
# free -mor
# top5. To make it appear even after reboot, put it into fstab
# echo "swapfile swap swap defaults 0 0" >> /etc/fstabIt will look like this:
# cat /etc/fstab
/swapfile1 swap swap defaults 0 0