SWAP Space Management in Linux

What is SWAP SPACE

SWAP space is an area of a disk which can be used for memory management subsystem. Swap space are used to supplement the system RAM by holding inactive pages of memory.

How to create a swap space:

To create a swap space, needs to do three things:

  1. Create partition.
  2. Set the type of the partition as82 Linux Swap.
  3. Format the type signature on the device.

How to create SWAP space

Create a 500 MiB SPAP space:

  1. Create a 500 MiB partition on/dev/vdbon Linux swap.

            # fdisk /dev/vdb

  1. Print the table, and then create a new partition that is 500 MiB in size.

            # p

            n

            # p

            # 1

            # +700M         (Enter size we want to create SWAP Space)

            # p

  1. Set new created partition to typeLinux swap.

            # t

            1

            L

            82

            p

  1. Save the partition table changes.

            # w

  1. Run thepartprobeto make the kernel aware of the partition table change.

            # partprobe

  1. Initiate the newly created partition as swap space.

            # mkswap /dev/vdb1

  1. Enable newly created swap space.

   7.1 To See created swap space is enable use following command.

            # free

   7.2 Enable created space as a SWAP space.

            # swapon /dev/vdb1

   7.3 Verify that the newly created swap space is available.

            # free

  1. Configure new swap space so that it is enable at boot.

    8.1 Determine UUID of the new swap partition on the first disk.

            # blkid /dev/vdb1

    8.2 Add an entry to /etc/fstab

            # vim /etc/fstab

            Paste here UUID        swap    swap    defaults           0          0

    8.3 Test enabling the swap space using the entry.

            # swapon –a

    8.4 Verify that the new swap space was enabled.

            # free