Create/Edit Swap Partition

Set-up Steps

  1. Check the free space

    free -m
  2. Create a partition

    dd if=/dev/zero of=$SWAPFILE_DIRECTORY bs=$COUNT count=$SPACE

$COUNT could be 1K \ 1M \ 1G etc.

$SPACE depends on your need, e.g. 1024

  1. Formation

    mkswap $SWAPFILE_DIRECTORY
    chmod -R 600 $SWAPFILE_DIRECTORY

  2. Turn it on

    swapon $SWAPFILE_DIRECTORY

  3. Enable it permanently

    1. Open /etc/fstab in the editor.

      vim /etc/fstab
    2. Add the line to it

      $SWAPFILE_DIRECTORY swap swap defaults 0 0

Last updated