How to add swap space to your system

As always, there is more than one way to add swap space to your system.

But this is how it worked for me:

  • Create a directory which holds the swap file
    sudo mkdir -p /var/cache/swap/
  • How much do you need / want? Let’s say 6GB
    sudo dd if=/dev/zero of=/var/cache/swap/6gb-swap-file bs=1M count=6144
  • We only want root to have access
    sudo chmod 600 /var/cache/swap/6gb-swap-file
  • Now we want to set it up as swap area
    sudo mkswap /var/cache/swap/6gb-swap-file
  • We need to tell the system
    sudo swapon /var/cache/swap/6gb-swap-file
  • Permanent mean to update /etc/fstab to ensure at next boot system still know about
    # swap added by "Super-User"
    /var/cache/swap/ 6gb-swap-file   none    swap    sw    0   0

Without the last step you can use the swap as long as you do not reboot the system;-)



Leave a Reply

Your email address will not be published. Required fields are marked *