How to Create and Add Swap File on Linux

Swap file is used by operating system to increase performance. Below are step by step guides how to create swap file in GNU Linux operating system:

  1. First of all, we determine the size of the new swap file and multiple it by 1024 to determine the block size. For example, the block size of a 64 MB swap file is 65536.
  2. After that, at a shell prompt as root, type the following syntax with count is being equal to the desired block size:
    dd if=/dev/zero of=/myswapfile bs=1024 count=65536
  3. And then create the swap file with this syntax:
    mkswap /myswapfile
  4. To enable the swap file immediately, execute this syntax:
    swapon /myswapfile
  5. To enable swap file at boot time, modify /etc/fstab file to include this line:
    /myswapfile swap swap defaults 0 0

    The next time the system boots, it will automatically enable the new swap file.

  6. To check the swap file we can use this command:
    cat /proc/swaps




    swapon -s

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.